Stable Release in branch 4.0
4.0.4
Released 18 Jun 2020
(6 years ago)
SoftwareServlet/Jakarta Servlet
Version4.0
Initial release4.0.0
15 Aug 2017
(8 years ago)
Latest release4.0.4
18 Jun 2020
(6 years ago)
Platform4.0.3-4.0.x: Jakarta EE 8
4.0.0-4.0.2: Java EE 8
Source codehttps://github.com/jakartaee/servlet/tree/4.0.4-RELEASE
Documentationhttps://javadoc.io/doc/jakarta.servlet/jakarta.servlet-api/4.0.4/index.html
Downloadhttps://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api/4.0.4
Servlet/Jakarta Servlet 4.0 ReleasesView full list

What Is New in Servlet 4.0

Servlet 4.0 is a major release that aligns with HTTP/2, introducing server push and other enhancements to modernize the Java web ecosystem.

Category Key Changes
New Features HTTP/2 Support, Server Push
API Improvements New PushBuilder interface, Mapping API enhancements
Requirements Mandates Java 8 or later

How does HTTP/2 change Servlet development?

The core of Servlet 4.0 is full support for HTTP/2. This isn't just about performance; it changes how we think about connections. Servlets can now handle multiplexed streams over a single connection, reducing latency.

In practice, you don't need to rewrite your servlets to benefit. The container handles the HTTP/2 protocol negotiation. Your existing HttpServletRequest and HttpServletResponse objects work as before, but they now operate over a more efficient transport layer.

What is the new PushBuilder for?

Server Push is HTTP/2's killer feature, and Servlet 4.0 gives you direct access to it via the PushBuilder interface. You get it from the HttpServletRequest object and use it to proactively send resources to the client.

This is perfect for pushing critical CSS, JavaScript, or images before the client even knows to ask for them. It cuts down on those round trips that slow down page loads. You use it right in your servlet's service method.

PushBuilder pb = request.newPushBuilder();
if (pb != null) {
    pb.path("styles.css").push();
}

Are there any improvements to mapping requests?

Yes, the mapping API got a useful upgrade. The new HttpServletMapping interface lets you inspect exactly how a request was matched to your servlet.

You can check the match type (e.g., exact, extension, wildcard), the pattern that was used, and the matched value. This is great for logging and for writing more dynamic servlets that need to understand their routing context.

What are the new service-ready requirements?

Servlet 4.0 containers must now support the addition of HTTP trailer fields. Trailers are headers sent after the response body, which is a feature of HTTP/2.

The spec also clarifies requirements around request/response content types and character encoding. This makes servlet behavior more predictable across different container implementations, which is something we appreciate when debugging.

FAQ

Do I need to change my existing servlets to work with Servlet 4.0?
No. All your existing servlets will continue to work unchanged. The HTTP/2 protocol handling is managed by the container. You only need to use new APIs like PushBuilder if you want to leverage new features.

Is server push automatic, or do I have to implement it?
You have to implement it. The container won't push resources automatically. You use the request.newPushBuilder() method to get a PushBuilder and explicitly define which resources to push to the client.

Can I use Servlet 4.0 with Java 11?
Yes. While the specification mandates a minimum of Java 8, it is fully compatible with Java 11 and later LTS versions. Your container (like Tomcat 9+) must be configured for the correct Java version.

What happens if a client doesn't support HTTP/2?
The servlet container automatically falls back to HTTP/1.1. Your servlet code doesn't need any conditional checks for this. The newPushBuilder() method will return null if the connection doesn't support server push.

Where can I find the official specification?
The Jakarta Servlet 4.0 specification is the definitive source. You can find the PDF and other resources at the official Jakarta EE website.

Releases In Branch 4.0

VersionRelease date
4.0.418 Jun 2020
(6 years ago)
4.0.321 Aug 2019
(6 years ago)
4.0.214 Jan 2019
(7 years ago)
4.0.120 Apr 2018
(8 years ago)
4.0.015 Aug 2017
(8 years ago)
4.0.0-b0702 Jun 2017
(9 years ago)
4.0.0-b0624 May 2017
(9 years ago)
4.0.0-b0529 Mar 2017
(9 years ago)
4.0.0-b0416 Mar 2017
(9 years ago)
4.0.0-b0302 Mar 2017
(9 years ago)
4.0.0-b0203 Feb 2017
(9 years ago)
4.0.0-b0109 Oct 2015
(10 years ago)