SE452: The Deployment Descriptor [2/20] ![]() ![]() ![]() |
Last week, we discussed the web application deployment descriptor, and looked at a few examples.
web.xml is an xml document, and the container requires that it not only be well-formed, but valid. It is checked against the DTD or Schema (for Servlets 2.4, optionally). The container should report errors in the web.xml file to the developer in a reasonable format. For Tomcat, this will be in the logs.
All images taken from the Servlet 1.4 specification
The web.xml structure:
The servlet node:
The servlet-mapping node:
The error-page node:
The env-entry node:
A concrete example:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>A Simple Application</display-name> <context-param> <param-name>Webmaster</param-name> <param-value>webmaster@mycorp.com</param-value> </context-param> <servlet> <servlet-name>catalog</servlet-name> <servlet-class>com.mycorp.CatalogServlet</servlet-class> <init-param> <param-name>catalog</param-name> <param-value>Spring</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>catalog</servlet-name> <url-pattern>/catalog/*</url-pattern> </servlet-mapping> <session-config> <session-timeout>30</session-timeout> </session-config> <mime-mapping> <extension>pdf</extension> <mime-type>application/pdf</mime-type> </mime-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> </welcome-file-list> <error-page> <error-code>404</error-code> <location>/404.html</location> </error-page> </web-app>