Servlets 2.5: Scream or yawn?

Tweet

It’s like a dream you try to remember but its gone,
Then you try to scream but it only comes out as a yawn

Pinch Me, Barenaked Ladies

JavaWorld yesterday published an article by Jason Hunter, the leading authority on Java Servlets. The article provides a pragmatic look at the changes in the recently finalized Servlet 2.5 specification (JSR 154).

At first glance, the updated spec may look pretty scary. Servlets form the foundation of almost all server-side Java Web development technology, and this latest update to the spec forces developers to use Java 5.0 (Servlets 2.4 worked on Java 1.3 or later) to take advantage of new language features like annotations.

Annotations allow you to pepper your Java classes, methods and properties with labels that are compiled into the resulting class files. When these classes are loaded, these annotations can identify how these classes, methods and properties should be used by the server. For example, one of the annotations supported by the Servlet 2.5 spec lets you tag a servlet class with the security role(s) that a user must have to access it.

In his article, Jason reveals that the changes in the spec are not as drastic as they may seem. The new annotations that are supported are in place primarily for use with Enterprise JavaBeans (EJBs), and non-EJB servers are not even required to support them. In fact, EJB-level functionality aside, anything that you can do with one of the new annotations you can still do with familiar instructions in your application’s web.xml file.

Where annotations may impact non-EJB developers is in the domain of performance. Any Servlet 2.5 compatible server that does support annotations will have to load all of the classes in your Web application at start-up in order to process the annotations they may contain. If you don’t plan to use annotations in your application, your web.xml file can disable annotation support by setting full="true" in the <web-app> tag so that your application’s classes will only be loaded by the server as needed.

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    version="2.5" full="true">
  ...
</web-app>

The remaining significant changes in the Servlet 2.5 spec add a couple of minor convenience features to the process of mapping servlets and filters to URLs in your web.xml file, and assist your applications in adding extentions to the HTTP protocol. Nothing worth losing sleep over, by any means.

The upshot of all this is that, from a practical standpoint, there is little reason for you to rush into moving your Java Web applications to the Servlet 2.5 specification. In fact, unless you plan to use the new EJB 3.0 standard for Enterprise JavaBeans, which relies on some of the annotation features of the spec, all Servlet 2.5 does for you is restrict you to deploying on platforms that support Java 5.0.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • ajking

    The really funny thing about Sun’s attempts to move the servlet spec up to 2.5 is that most of the servlet and JSP web hosting still being offered to the public at large makes use of Tomcat 4.x, which supports only Servlet 2.3. The major web hosting control panel suppliers like Ensim and Plesk are now two levels behind in their support of the latest Java web specs. Plesk plans support for Tomcat 5.0 (which works with Servlet 2.4) sometime in February or March of this year with Plesk 8 for *nix. So outside of enterprise deployments of EJB app servers, Servlet 2.5 won’t cause a ripple.

  • bonefry

    Yes, but eventualy people will move to version 2.5
    Of course it takes a long time … because we are talking mostly about enterprise applications that have a long life.
    And Java EE 5 has lots of others improvments, EJB 3 and Servlet 2.5 are just a small part of it.