Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

What's new in Java Servlet API 2.2?

A full update on the latest Java Servlet API

  • Print
  • Feedback
On August 23, Sun Microsystems published the first public release of the specification for Java Servlet API 2.2 (see the Resources section below for a link to the formal specification). Included in the specification are some very exciting enhancements to servlets. This article describes what's new in version 2.2 of the API, explains the decision-making process behind the changes, and demonstrates how to write servlets using API 2.2 features. To keep the article somewhere near a reasonable length, I'm going to assume that you're familiar with the classes and methods of previous versions of the Java Servlet API. If that's not the case, you can peruse Resources for links to sites that will help get you up to speed.

Java Servlet API 2.2 includes many enhancements that make servlets more powerful than ever:

  • Servlets are now part of the Java 2 Platform, Enterprise Edition specification

  • Servlets now embrace the notion of pluggable Web applications, which can be configured and deployed in a server-independent manner

  • Rules have been provided that define how servlets can be distributed across multiple back-end servers

  • Response output buffering has been added

  • Control over HTTP headers has been enhanced

  • New styles of request dispatching have been added

  • More advanced error handling can now be used

  • Several method signatures have been changed to keep the API consistent



Before we begin our examination of these enhancements, let me point out that version 2.2 has been released as a specification only; no Web server yet supports it. Even Sun's official reference implementation is still perhaps a couple months away; it is expected to be released with source code as part of the Jakarta Project (see Resources for information on Jakarta). So be careful, boys and girls; don't try these code examples at home!

Java 2 Platform, Enterprise Edition

One of the first things one notices when reading the Java Servlet API 2.2 specification is that the term servlet engine has been replaced by servlet container. This minor change is indicative of a larger one: the Java Servlet API is now a required API of the Java 2 Platform, Enterprise Edition (J2EE) specification and, throughout J2EE's terminology, container is preferred over engine. The addition of servlets to J2EE has no real effect on pure servlet developers (except for the fact that we have to stop saying "engine"). But it does guarantee that enterprise developers using J2EE will always have support for servlets. (Lucky developers!)

Web applications

Java Servlet API 2.2 includes one new feature so significant it may change the way the Web works. That feature: Web applications.

A Web application, as defined in the servlet specification, is a collection of servlets, JavaServer Pages (JSPs), HTML documents, images, and other Web resources that are set up in such a way as to be portably deployed across any servlet-enabled Web server. Installing a Web app is simple. Gone are the days of detailed instruction sheets telling you how to install third-party Web components, with different instructions for each type of Web server. With Web apps, the entire application can be contained in a single archive file and deployed by placing the file into a specific directory.

  • Print
  • Feedback

Resources