Thursday, July 31, 2008

Servlet 3.0 - A comprehensive study and example

Servlet 3.0 is an overhaul to the ageing servlet technology. The features I liked in the servlet 3.0 are:
- Making web.xml optional, I really dislike handling 'BOILER PLATE' XML while coding. By using declarative style of programming(To java 5/6/7 people this is pretty old now) it is much easier and fun writing a servlet - bootstrappers will like it much. I will just show you one code snippet using servlet 3.0 that just works.

package org.objectengineering.exp.servlet3;
import javax.servlet.http.annotation.*;


@Servlet(urlMappings={"/foo"})
public class MyFirstServlet3 {
}

Thats it. Try it on a servlet 3.0 capable container like jetty 7.0. While writing this post the latest jetty was 7.0.0-pre1. Your servlet writing is over - can't believe ;) - go and deploy it now - you can skip the web.xml part. done.

Greg Wilkins proposal for asynchronous servlet is interesting and I am looking for its adoption by JSR expert commitee. The proposal can be found at http://dist.codehaus.org/jetty/misc/AsyncServlet3.0-draft0.html.

No comments: