JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy
  • Contact Us

Deployment Descriptor in Different Servlet Versions

November 26, 2013 by Krishna Srinivasan Leave a Comment

Servlet specifications evolved over the period of time. There is lot of improvements has been added to the web deployment descriptor as part of the new versions. It is important for the Java developers to understand the new elements in the web.xml and utilize the added features.

Servlet Web Deployment Descriptor
Servlet Web Deployment Descriptor

In this tutorial I will summarize the sample snippet from the list of web.xml file used in the previous versions of servlet. Primarily I have listed the XML schema that have updated on different versions of servlet. This will help you to understand the evolution of servlet configuration file and the latest improvements. If you have any questions, please write it in the comments section.

  • New Features in Servlet 3.0
  • What is load on startup element in web.xml file

1. Servlet 2.3

This version uses the Document Type Definition (DTD) validation for the web.xml validation. This is the traditional way of validation before the XML schema validation. After the XSD’s introduction, it is not recommended to use DTD.

[code lang=”xml”]
<!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 Sample Application</display-name>
</web-app>
[/code]

2. Servlet 2.4

First time in Servlet 2.4, XSD is used for the validation of XML contect. This version of the deployment descriptor is used for long time and become most popular.

[code lang=”xml”]
<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">
<web-app>
<display-name>Servlet 2.4 Sample Application</display-name>
</web-app>
[/code]

3. Servlet 2.5

In the version XML namspace changed from J2EE to JavaEE as http://java.sun.com/xml/ns/javaee.

[code lang=”xml”]
<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">
<web-app>
<display-name>Servlet 2.5 Sample Application</display-name>
</web-app>
[/code]

4. Servlet 3.0

This is the latest major servlet release with lot of advanced features. Not most of the projects are adopted this version. Still most of the projects are using Servlet 2.5 version.

[code lang=”xml”]
<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">
<web-app>
<display-name>Servlet 3.0 Sample Application</display-name>
</web-app>
[/code]

Filed Under: Java EE Tagged With: Servlets, web.xml

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved