January 2018
Intermediate to advanced
350 pages
9h 7m
English
Servlet 4.0 specification brings HTTP/2 support, which is new for Java EE and for a lot of applications. The idea is to be able to eagerly push some resources to the client. Here is a basic example to give you a high-level picture in mind:
@WebServlet("/packt")public class PacktServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PushBuilder pushBuilder = req.newPushBuilder(); pushBuilder .path("images/packt.png") .addHeader("content-type", "image/png") .push(); // serve the response which can use images/packt.png }}
This Servlet will start pushing the resource images/packt.png upfront. This will enable the browser to rely on it ...
Read now
Unlock full access