web.xml file


 

+

Search Tips   |   Advanced Search

 

Deployment information for Web components, including...

...can be found in...

install_root/appname.war/WEB-INF/web.xml

The Java Servlet spec defines the web.xml deployment descriptor file in terms of an XML schema document. For backwards compatibility of applications written to the Java Servlet 2.2 Specification, Web containers are also required to support the Java Servlet 2.2 specification. For backwards compatibility of applications written to the Java Servlet 2.3 specification, Web containers are also required to support the Java Servlet 2.3 specification.

 

Sample web.xml

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

<web-app id="WebApp_9" 
            version="2.4" 
            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">

  <display-name>Servlet 2.4 application</display-name>

  <filter>
    <filter-name>ServletMappedDoFilter_Filter</filter-name>
    <filter-class>tests.Filter.DoFilter_Filter</filter-class>
    <init-param>
      <param-name>attribute</param-name>
      <param-value>tests.Filter.DoFilter_Filter.servlet_mapped</param-value>
      </init-param>
  </filter>

  <filter-mapping>
    <filter-name>ServletMappedDoFilter_Filter</filter-name>
    <url-pattern>/DoFilterTest</url-pattern>
    <dispatcher>REQUEST</dispatcher>
  </filter-mapping>

  <filter-mapping>
    <filter-name>ServletMappedDoFilter_Filter</filter-name>
    <url-pattern>/IncludedServlet</url-pattern>
    <dispatcher>INCLUDE</dispatcher>
  </filter-mapping>

  <filter-mapping>
    <filter-name>ServletMappedDoFilter_Filter</filter-name>
    <url-pattern>ForwardedServlet</url-pattern>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>

  <listener>
    <listener-class>tests.ContextListener</listener-class>
  </listener>

  <listener>
    <listener-class>tests.ServletRequestListener.RequestListener</listener-class>
  </listener>

  <servlet>
    <servlet-name>welcome</servlet-name>
    <servlet-class>WelcomeServlet</servlet-class>
  </servlet>

  <servlet>
    <servlet-name>ServletErrorPage</servlet-name>
    <servlet-class>tests.Error.ServletErrorPage</servlet-class>
  </servlet>

  <servlet>
    <servlet-name>IncludedServlet</servlet-name>
    <servlet-class>tests.Filter.IncludedServlet</servlet-class>
  </servlet>

  <servlet>
    <servlet-name>ForwardedServlet</servlet-name>
    <servlet-class>tests.Filter.ForwardedServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>welcome</servlet-name>
    <url-pattern>/hello.welcome</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>ServletErrorPage</servlet-name>
    <url-pattern>/ServletErrorPage</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>IncludedServlet</servlet-name>
    <url-pattern>/IncludedServlet</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>ForwardedServlet</servlet-name>
    <url-pattern>/ForwardedServlet</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>hello.welcome</welcome-file>
  </welcome-file-list>

  <error-page>
    <exception-type>java.lang.ArrayIndexOutOfBoundsException</exception-type>
    <location>/ServletErrorPage</location>
  </error-page>

  <error-page>
    <error-code>404</error-code>
    <location>/error404.html</location>
  <error-page>

</web-app>

For each <error-page> declaration, choose either <exception-type> or<error-code>, but not both. The <location> tag is required.

 

Portlet note

If we use RAD v6 to create portlets, remove references to std-portlet.tld...

<taglib id="PortletTLD">
  <taglib-uri>http://java.sun.com/portlet</taglib-uri>
  <taglib-location>/WEB-INF/tld/std-portlet.tld</taglib-location>
</taglib>




Related concepts

Web apps
Web modules
Assembly tools

 

Related tasks

View Web services deployment descriptors in the admin console
View deployment descriptors

 

Related

Web apps: Links

 

Related information

Servlets