
part from the addition of functionalities such as
filters and web application events, the Servlet specificationone of the key Java APIs for web application developmenthas not undergone any major changes since its introduction. However, the specification has remained robust, and the release of the new Servlet 3.0 specification (
JSR 315) will affect a major change in the way developers build Java web applications.
This article offers a brief overview to the new features in Servlet 3.0. Then, using code samples, it dives into the details of using annotations for Servlet 3.0 filters and listeners. The discussion also touches on how to plug frameworks and other libraries into a web application using web fragments. The article concludes with a brief discussion of Servlet 3.0's support for asynchronous processing and highlights of the enhancements made to the existing APIs.
The New Features in Servlet 3.0: An Overview
The Servlet 3.0 specification has three goals for the developers who employ it:
- Simplicity
- Ease of development
- Adherence to Web 2.0 principles
To make the development process easier, Servlet 3.0 introduces annotations. Similar to the changes in EJB 3.1, the introduction of annotations makes the web deployment descriptor –web.xml optional.
Pluggability
Whenever you use a third-party framework such as Struts, JSF, or Spring, you need to have a corresponding entry for the respective Servlet in
web.xml. This requirement makes the web deployment descriptor cumbersome and difficult to maintain. Enter the new pluggability feature in Servlet 3.0, which makes web applications modular and easier to maintain. Implemented through web fragments, pluggability relieves the developer from making too many Servlet configuration entries in the
web.xml file.
Asynchronous Processing
Another significant change in the new Servlet specification is the support for asynchronous processing, a useful feature for AJAX applications. When a Servlet creates a thread to make a request, it often has to wait for a response from a resource like a database or message connection before it can perform another operation on that thread. Asynchronous processing avoids such blocking requests by allowing the thread to perform some other operation.
Apart from the features mentioned here, several other enhancements have been made to the existing API. The sections towards the end of the article will explore these features one by one in detail.
Author's Note: To run a Servlet developed with Servlet 3.0, your Servlet container should run Java SE 6 and above. |