web.xml file

The web.xml file provides configuration and deployment information for the web components that comprise a web application.

The Java™ Servlet specification defines the web.xml deployment descriptor file in terms of an XML schema document. For backwards compatibility, any web.xml file that is written to Servlet 2.2 or later that worked in previous versions of WebSphere® Application Server are supported by the web container.

If you use Rational® Application Developer Version 6 to create your portlets, you must remove the following reference to the std-portlet.tld from the web.xml file:
<taglib id="PortletTLD">
  <taglib-uri>http://java.sun.com/portlet</taglib-uri>
  <taglib-location>/WEB-INF/tld/std-portlet.tld</taglib-location>
</taglib>

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.

[z/OS][AIX Solaris HP-UX Linux Windows]For example, if the application is client.war, then the web.xml file is placed in the install_root/client war/WEB-INF directory.

[IBM i]For example, if the application is client.war, then the web.xml file is placed in the profile_root/installedApps/cellName/client.ear/client.war/WEB-INF directory (in a default installation), where the edition is either base or WebSphere Application Server Network Deployment, depending on which edition you are using.

Usage notes

  • Is this file read-only?

    No

  • Is this file updated by a product component?

    This file is updated by the assembly tool.

  • If so, what triggers its update?

    The assembly tool updates the web.xml file when you assemble web components into a web module, or when you modify the properties of the web components or the web module.

  • How and when are the contents of this file used?

    WebSphere Application Server functions use information in this file during the configuration and deployment phases of web application development.

Supported configurations: The web.xml file does not represent the entire configuration that is available for the web application. There are other servlets filters, and listeners that can be defined using programmatic configurations, annotations, and web fragments.
Avoid trouble: Marking the web application metadata complete will prevent annotations and web fragments from being able to configure components.

Sample file entry

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="3.0" 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">
	<display-name>Servlet 3.0 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>
Best practice: For each <error-page> declaration, select either <exception-type> or <error-code>, but not both. The <location> tag is required.