Java
Article
By Kevin Yank

Servlets 2.5: Scream or yawn?

By Kevin Yank
Last chance to win! You'll get a... FREE 6-Month Subscription to SitePoint Premium Plus you'll go in the draw to WIN a new Macbook SitePoint 2017 Survey Yes, let's Do this It only takes 5 min

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).

--ADVERTISEMENT--

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.

Login or Create Account to Comment
Login Create Account
Recommended
Sponsors
Get the most important and interesting stories in tech. Straight to your inbox, daily.