Overview of different Servlet versions

Overview of different Servlet versions


Posted in : Servlet Posted on : October 29, 2010 at 5:21 PM Comments : [ 0 ]

In this tutorial you will learn about different servlet specifications

Different Servlet Specifications

There are many servlet version has been introduced from begnig till today. The specification for that version is as follows

Servlet 2.1

This version was introduced over servlet 2.0 to remove its some drawbacks. This servlet specification provides the following feature over servlet 2.0

ConsistentLogging

It makes more consistent logging, it the method ServletException.log(Exception exception, String message) has been deprecated in and a new method log(String message, Throwable throwable) was introduced

Removed Redundancy

The method ServletRequest.getRealPath(String path) is deprecated in servlet 2.1. In servlet 2.0 specification both method ServletRequest.getRealPath(String path) and ServletContext are used. In servlet 2.1 specification only ServletContext is used.

Easy Initialisation

In servlet 2.0 specifications, to initialize a servlet you need to call  init(ServletConfig config) and then we must call super.init(config), but in servlet 2.1 specifications you can override init() method and super.init(config) is mendatory.

Simple To getSession

The 2.1 specification also add no-argument version of getSession() method. Its default value is true. while in servlet 2.0 specification, it was compulsory  to call getSession(true).

Servlet 2.2

Servlet 2.2 specification has been released as specification only. No web server support is given yet.

The new feature included in servlet 2.2 specification which may change the way of work is Web Application.

This represents a single web application, it is a collections of servlet, Java Server Pages (JSP), HTML, Images and other web resources. It is very  simple to install the Web Application, installation. you have to place only war file in a specific directory. This war file bundles the following things

ndex.html
howto.jsp
feedback.jsp
images/banner.gif
images/jumping.gif
WEB-INF/web.xml
WEB-INF/lib/jspbean.jar
WEB-INF/classes/MyServlet.class
WEB-INF/classes/com/mycorp/frontend/CorpServlet.class
WEB-INF/classes/com/mycorp/frontend/SupportClass.class

Here the WEB-INF directory is special, it contains all the java classes of a web application and a xml file for mapping these java classes. The directory META-INF contains the meta information meta information about archive contents.

Servlet 2.3

Servlet have now dependant on J2SDK 1.2 or JDK 1.2 from its 2.3 specification. This specification have added many new features into the servlet. Some of the important feature are -

Filter

Filter is most important part of the servlet, they are not actually a servlet, they actually creates a request response object to the servlet. They preprocess the request coming to the servlet and postproccesses the response generated the servlet. They can perform the following task

  • They intercepts the servlet invocation
  • Examines the request object
  • They can modify the request header and request data.
  • They can modify the response data and header.
  • They intercepts the servlet invocation after a servlet is called.
Lifecycle Events

This is the second more significant advantage of servlet 2.3. Any listener interested in observing ServletContext can implement the ServletContextListener interface. This interface have two methods

  1. void contextInitialized(ServletContextEvent event) - This method is called when application is initialized first.
  2. void contextDestroyed(ServletContextEvent event) - This method is called when application is destroyed

Servlet 2.4

There are many feature added in servlet 2.4 This specification enhanced may classes and interfaces.

  • The new feature added in ServletRequest interface are as

getRemotePort() - returns the IP address of the client

getLocalName() - returns the host name on which the request was received.

getLocalAddr()- returns the IP address of the machine on which request was recieved

getLocalPort() - returns the port number.

  • New feature has been added in RequestDispatcher interface

In the servlet 2.4 specification there are some extra attribute added in servlet 2.4  they are -

javax.servlet.forward.request_uri
javax.servlet.forward.context_path
javax.servlet.forward.servlet_path
javax.servlet.forward.path_info
javax.servlet.forward.query_string

  • Single Thread model have been deprecated in Servlet 2.4 specification.
  • New methods HttpSession.logout() has been added in Session interface. and now session allows to to accept zero and negative value.

Servlet 2.5

Servlet 2.5 is the newest specification. To use this feature you must have jdk 1.5 version or above than this. The servlet 2.5 doesn't supports the lover version than jdk 1.5. It has added many features in servlet 2.4

  • Added Annotations supports- The annotations provides a mechanism with metadata for to decorate java codings. They actually a mark code in such a way that processor may alter their behavior.
  • Added convenience web.xml - This specification added many small changes in web.xml. This makes it more convenience for developers. for example we do in filter mapping as

In early version write filter mapping as

<filter-mapping>
<filter-name>FilterName</filter-name>
<servlet-name>FilterName</servlet-name>
</filter-mapping>

In Servlet 2.5

<filter-mapping>
<filter-name>FilterName</filter-name>
<servlet-name>*</servlet-name>
</filter-mapping>        

In previous version of filter mapping or servlet mapping we give only one URL Pattern, but in this specification we can give many URL Pattern.

<servlet-mapping>
<servlet-name>url</servlet-name>
<url-pattern>/url/*</url-pattern>
<url-pattern>/url/*</url-pattern>
</servlet-mapping>

  • A Handful of removed restrictions- Servlet 2.5 have added some restrictions around session tracking and error handling. It removed the restriction that error page could not call the setStatus() method to alter the error code. In session tracking it has made a convenient rule that the servlet called by RequestDispatcher() can not set the response header.
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics