Tuesday, July 17, 2012

web.xml deployment descriptor for diffrent sevlet versions

today i am gong to discuss the different web.xml deployment descriptors available for each servlet API versions. hope this might be helpful for you to decide the correct web.xml DD definition base on the servlet API version you are using.

1. Servlet 2.3 Deployment Descriptor

For Servlet 2.3, using a dtd file to validate the XML content. Not recommend to use, consider upgrading to version 2.4 or 2.5.

P.S Maven 3′s quick start web app is still generating this

web.xml -> Namespace = none
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
 
<web-app>
  <display-name>Servlet 2.3 Web Application</display-name>
</web-app>
 
 

2. Servlet 2.4 deployment descriptor

For Servlet 2.4, using xsd to validate XML content, the most popular web.xml version.
web.xml -> Namespace = http://java.sun.com/xml/ns/j2ee
 
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
       http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
       version="2.4">

  <display-name>Servlet 2.4 Web Application</display-name>
</web-app>
 
 

3. Servlet 2.5 deployment descriptor

For Servlet 2.5, using xsd to validate XML content, from this version and onward, the namespace is changed.

web.xml -> Namespace = http://java.sun.com/xml/ns/javaee
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
       http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
       version="2.5">

  <display-name>Servlet 2.5 Web Application</display-name>
</web-app>
 
 

4. Servlet 3.0 deployment descriptor

For Servlet 3.0, with xsd validation also, the latest version, but not many people using it.

web.xml -> Namespace = http://java.sun.com/xml/ns/javaee
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
       http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
       version="3.0">

  <display-name>Servlet 3.0 Web Application</display-name>
</web-app>
 
 
 
hope this will helpful for you !!!


Regards
Chathuranga Tennakoon
chathuranga.t@gmail.com

references 
http://www.mkyong.com/web-development/the-web-xml-deployment-descriptor-examples/

2 comments: