web.xml file

The web.xml file provides configuration and deployment information for the Web components that comprise a Web application. Examples of Web components are servlet parameters, servlet and JavaServer Pages (JSP) definitions, and Uniform Resource Locators (URL) mappings.

The servlet 2.3 specification dictates the format of the web.xml file, which makes this file portable among Java Two Enterprise Edition (J2EE) compliant products.

Location

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. For example, if the application is client.war, then the web.xml file is placed in the install_root/client war/WEB-INF directory.

Usage notes

Sample file entry

<?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>Peristence 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>

Related reference
Web applications: Resources for learning