HTTP/2 server push support
HTTP/2 is the newest version of the HTTP protocol. It offers several advantages over HTTP 1.1. For example, with HTTP/2 there is a single connection between the browser and the server, and this connection remains open until the user navigates to another page. HTTP/2 also offers multiplexing, meaning that several concurrent requests from the browser to the server are allowed. Additionally, HTTP/2 features server push, meaning that the server can send resources to the browser without the browser specifically having to request them.
HTTP/2 server push support was added to the servlet specification in version 4.0, released as part of Java EE 8. In this section, we’ll see how we can write code to take advantage of HTTP/2’s server push functionality. The following example illustrates how this can be done:
package com.ensode.jakartaeebook.servlet; //imports omitted @WebServlet(name = "ServletPushDemoServlet", urlPatterns = {"/ServletPushDemoServlet...