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” (@ http://java.sun.com/products/servlet), 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="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" metadata-complete="true">

  <servlet>
    <servlet-name>Test</servlet-name>
    <servlet-class>TestServlet</servlet-class>
  </servlet>

  <servlet>
    <servlet-name>Query</servlet-name>
    <servlet-class>QueryServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>Test</servlet-name>
    <url-pattern>/Echo</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>Query</servlet-name>
    <url-pattern>/Query</url-pattern>
  </servlet-mapping>
</web-app>

Explanation:

  • 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.

About lorddisk

WebCenter Content, WebCenter Portal, WebCenter Sites,Weblogic, Identity and Access Management (IAM),SSO,OAM,OIM,OAAM,OUD, OPAM,OID, OVD ,Oracle API Gateway ,OBIEE,OEDQ, Oracle ADF, Oracle SOA,J2EE, CackePHP ,PHP,J2SE,J2EE,Spring,Hibernate,JQuery,CSS,Java Script ,Joomla,Drupal,Worpress
This entry was posted in java and tagged , . Bookmark the permalink.

1 Response to Web Application Deployment Descriptors – “web.xml”

  1. Cheri says:

    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 to Cheri Cancel reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

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