Web Application Deployment Descriptors – “web.xml”

he “web.xml” contains the deployment descriptors. There are two sets of web.xml


  1. $CATALINA_HOME\conf\web.xml: applicable to all web application under Tomcat.
  2. WebContextRoot\WEB-INF\web.xml: applicable to the specific web context. It overrides the global setting, if any.

The complete specification for “web.xml” can be found in the “Java Servlet Specification” (@, under “Deployment Descriptor”.

Suppose that you wish to deploy two servlets: TestServlet.class and QueryServlet.class (that have to be kept under your application’s “WebContextRoot\WEB-INF\classes” directory):

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns=""
  version="3.0" metadata-complete="true">






  • Each servlet requires two configuration elements. A <servlet> to specify the servlet-name and the servlet-class, and a <servlet-mapping> to specify the URL for that particular servlet-name. In the above example, the TestServlet can be referenced via URL http://host:port/context-path/Echo, and the QueryServlet via URL http://host:port/context-path/Query.
  • You have to list ALL the <servlet> elements first, followed by <servlet-mapping> elements.

One thought on “Web Application Deployment Descriptors – “web.xml”

  1. I personally contemplate the reasons why you labeled this blog post, “Web Application Deployment Descriptors – web.

    xml Stay Hungry Stay Foolish”. In any event I loved the post!
    Thanks a lot,Rosalind

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s