Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 14 java ee 8 Gone is the need to shard resources across domains to get around browser TCP connection limitations Simply specify the resources and let the server handle delivery This is the way it should always have been With the resources already in the browsers cache the browser can render the page much more quickly With a typical web page requiring more than 100 resources its easy to see how much of an opportunity this represents for performance enhancements Server Push in Action Servlets are the backbone technology behind the Java EE web application tier They provide the server capabilities that form the basis of many frameworks JavaServer Faces JSF relies on the FacesServlet to manage the request processing lifecycle for web applications and JSP pages are translated into servlets upon the first client request so it should be no wonder that servlets are the natural place to expose the HTTP 2 Server Push abstraction That abstraction is represented as a PushBuilder object and is created by calling the newPushBuilder method from the HttpServletRequest instance passed to all overridden request handling methods With a PushBuilder instance you can start pushing the resources required by the requested web page The resource is set on the PushBuilder instance by passing its location to the path method The resource is pushed to the client by invoking the push method It can be reused to send as many resources as required Listing 1 and Listing 2 show the simplest example that uses Server Push Listing 1 shows an HTTP servlet that responds to a GET request to the URI simplestexample Listing 1 @ WebServlet simplestexample public class SimplestExample extends HttpServlet @ Override protected void doGet HttpServletRequest request HttpServletResponse response throws ServletException IOException
You must have JavaScript enabled to view digital editions.