web.xml
一个完整的示例
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<!-- 定义了WEB应用的名字 -->
<display-name>ServletPractice</display-name>
<!-- 声明WEB应用的描述信息 -->
<description>this is a servlet practice</description>
<!-- context-param元素声明应用范围内的初始化参数 -->
<context-param>
<description></description>
<param-name></param-name>
<param-value></param-value>
</context-param>
<!-- servlet API的版本2.3增加了对事件监听程序的支持,事件监听程序在建立、修改和删除会话或servlet环境时得到通知。 Listener元素指出事件监听程序类 -->
<listener>
<description></description>
<listener-class>com.devil.</listener-class>
</listener>
<!-- 过滤器元素将一个名字与一个实现javax.servlet.Filter接口的类相关联 -->
<filter>
<description></description>
<filter-name>TestFilter</filter-name>
<filter-class></filter-class>
<init-param>
<description></description>
<param-name></param-name>
<param-value></param-value>
</init-param>
</filter>
<!-- 一旦命名了一个过滤器,就要利用filter-mapping元素把它与一个或多个servlet或JSP页面相关联 -->
<filter-mapping>
<filter-name>TestFilter</filter-name>
<url-pattern></url-pattern>
</filter-mapping>
<!-- 在向servlet或JSP页面制定初始化参数或定制URL时,必须首先命名servlet或JSP页面。Servlet元素就是用来完成此项任务的 -->
<servlet>
<description></description>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.devil.servlet.practice.UploadFile</servlet-class>
<init-param>
<description></description>
<param-name></param-name>
<param-value></param-value>
</init-param>
<load-on-startup></load-on-startup>
</servlet>
<!-- 服务器一般为servlet提供一个缺省的URL:http://host/webAppPrefix/servlet/ServletName。
但是,常常会更改这个URL,以便servlet可以访问初始化参数或更容易地处理相对URL。在更改缺省URL时,使用servlet-mapping元素 -->
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>*.api</url-pattern>
</servlet-mapping>
<!-- 指示服务器在收到引用一个目录名而不是文件名的URL时,使用哪个文件 -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 在返回特定HTTP状态代码时,或者特定类型的异常被抛出时,能够制定将要显示的页面 -->
<error-page>
<error-code>404</error-code>
<location>/*</location>
</error-page>
<error-page>
<exception-type></exception-type>
<location>/*</location>
</error-page>
<!-- MIME类型配置 -->
<mime-mapping>
<extension></extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<!-- 会话超时配置(单位为分钟) -->
<session-config>
<session-timeout>120</session-timeout>
<cookie-config></cookie-config>
<tracking-mode>URL</tracking-mode>
</session-config>
<!-- 安全限制配置 -->
<security-constraint>
<display-name></display-name>
<web-resource-collection>
<web-resource-name></web-resource-name>
<description></description>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<description></description>
<role-name></role-name>
</auth-constraint>
</security-constraint>
</web-app>