Upgraded supports for Http, J2SE, and J2EE: Servlet 2.4 depends on Http1.1 and J2SE 1.3.
Difference between Servlet 2.5 and Servlet 2.4
Features of Servlet 2.4
Upgraded supports for Http, J2SE, and J2EE: Servlet 2.4 depends on Http1.1
and J2SE 1.3.
Additional ServletRequest methods : In Servlet 2.4 four new methods are
added in the ServletRequest
getRemotePort(): It returns the IP source port of the client.
getLocalName(): It returns the host name on which the request was
getLocalAddr(): It returns the IP address on which the request was
getLocalPort(): It returns the IP port number.
New Support for internationalization and charset choice:
support of internationization Servlet 2.4 has added to new methods in the
setCharacterEncoding(String encoding): The purpose of this method is
to set the response's character encoding. This method
helps us to pass a charset parameter to setContentType(String) or
passing a Locale to setLocale(Locale). We can now avoid setting the
charset in the setContentType("text/html;charset=UTF-8") as
setCharacterEncoding() methods pairs with the preexisting
getCharacterEncoding() method to manipulate and view the response's
getContentType(): It is responsible for returning the response's
content type. The content type can be dynamically set with a
combination of setContentType(), setLocale(), and setCharacterEncoding()
calls, and the method getContentType() provides a way to view the
generated type string.
New features has been added in RequestDispatcher: In Servlet 2.4 five new
request attributes has been added to provide the extra information during a
RequestDispatcher forward() call. This features has been added is Servlet
2.4 to know the true original request URI. The following request attributes
SingleThreadModel interface has been deprecated: In
Servlet 2.4 the SingleThreadModel interface has been deprecated.
HttpSession details and interaction with logins has been clarified:
The new method HttpSession.logout() has been added in the Servlet 2.4.
Now session allows zero or negative values in the <session-timeout>
element to indicate sessions should never time out.
If the object in the session can't be serialized in a distributed
environment then it must throw an IllegalArgumentException.
Welcome file behavior and Classloading has been
clarified: In servlet 2.4 welcome file can be servlets.
The web.xml file now uses XML Schema: Version
2.4 servers must still accept the 2.2 and 2.3 deployment descriptor formats,
but all new elements are solely specified in Schema.
Features of Servlet 2.5
This version has been released on September 26, 2005
by the Sun MicroSystems. It is not necessary that all web servers and
application servers support the features of Servlet 2.5. Still most of
the popular containers like Tomcat 5.5 and JBoss 4.0 still support
The list of the added features is given below:
Dependency on J2SE 5.0: The minimum platform
requirement for Servlet2.5 is JDK 1.5. Servet2.5 can't be used in versions
below that JDK1.5. All the available features of Jdk1.5 like generics,
autoboxing, an improved for loop etc, etc are guaranteed available to
Support For annotations: Annotations provide a
mechanism for decorating java code constructs (classes, methods, fields,
etc.) with metadata information. Annotations are mark code in such a way
that code processors may alter their behavior based on the metadata
Several web.xml convenience: Servlet 2.5 introduces
several small changes to the web.xml file to make it more convenient to
use. For example while writing a <filter-mapping>, we can now
use a asterisk in a <servlet-name> which will represent all servlets
as well as Jsp.
Apart from these changes, many more facilities added in web.xml.
A Handful of removed restrictions: Servlet 2.5
removed a few restrictions around error handling and session tracking. Now
it has removed the restriction that the <error-page> could not call
the setStatus() method to alter the error code that triggered them. In
session tracking, Servlet 2.5 eased a rule that a servlet called by
RequestDispatcher include() couldn't set response headers.
Some edge case clarifications: : The servlet2.4
specification says that before calling request.getReader() we must
call request.setCharacterEncoding(). However there is no such
clarification given why it is so. It has been described properly in Servlet