web.xml deployment descriptor

 

Overview

The web.xml deployment descriptor file provides configuration information for the Web components that comprise a web application (*.war). The servlet 2.3 specification dictates the format of the web.xml file, which makes this file portable among J2EE compliant products.

The web.xml file must reside in the WEB-INF directory under the context of the hierarchy of directories that exist for a web application (.war). For example, if the application is client.war, then the web.xml file is placed in...

$WAS_HOME/client.war/WEB-INF

This file can be updated using many tools, such as Rational Application Developer and the Assembly Toolkit.

 

web.xml Sample

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app 
             PUBLIC 
             "-//Sun Microsystems, Inc.  //DTD Web Application 2.3//EN"
             "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">

   <web-app id="WebApp_1">

      <display-name>Persistence Manager Web Client</display-name>

      <description>Persistance Manager Web Client</description>

      <servlet id="Servlet_1">
         <servlet-name>CustomerLocalServlet</servlet-name>
         <description>Local Customer Servlet</description>
         <servlet-class>CustomerLocalServlet</servlet-class>
      </servlet>

      <servlet id="Servlet_2">
         <servlet-name>CustomerServlet</servlet-name>
         <description>Remote Customer Servlet</description>
         <servlet-class>CustomerServlet</servlet-class>
      </servlet>

      <servlet id="Servlet_3">
         <servlet-name>CreditCardServlet</servlet-name>
         <description>Credit Card Servlet - PM Verification</description>
         <servlet-class>CreditCardServlet</servlet-class>
      </servlet>

      <servlet-mapping id="ServletMapping_1">
         <servlet-name>CustomerLocalServlet</servlet-name>
         <url-pattern>/CustomerLocal</url-pattern>
      </servlet-mapping>

      <servlet-mapping id="ServletMapping_2">
         <servlet-name>CustomerServlet</servlet-name>
         <url-pattern>/Customer</url-pattern>
      </servlet-mapping>

      <servlet-mapping id="ServletMapping_3">
         <servlet-name>CreditCardServlet</servlet-name>
         <url-pattern>/CreditCard</url-pattern>
      </servlet-mapping>

      <welcome-file-list id="WelcomeFileList_1">
         <welcome-file>index.html</welcome-file>
      </welcome-file-list>

      <security-role id="SecurityRole_1">
         <description>Everyone role</description>
         <role-name>Everyone Role</role-name>
      </security-role>

      <security-role id="SecurityRole_2">
         <description>AllAuthenticated role</description>
         <role-name>All Role</role-name>
      </security-role>

      <security-role id="SecurityRole_3">
         <description>Deny all access role</description>
         <role-name>DenyAllRole</role-name>
      </security-role>

  </web-app>

 

See Also

Webapplications: Resources for learning