<?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" version="3.0">
<display-name>hujing</display-name>
<!-- 欢迎页面,从上到下依次寻找 -->
<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>
<!-- 将值放入ServletContext中 -->
<context-param>
<param-name>name</param-name>
<param-value>value></param-value>
</context-param>
<!-- 注册servlet -->
<servlet>
<servlet-name>aaa</servlet-name>
<servlet-class>servlet.AServlet</servlet-class>
<!-- 为这个Servlet的ServletConfig设置初始参数 -->
<init-param>
<param-name>name</param-name>
<param-value>123</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>aaa</servlet-name>
<!-- url可以有多种写法,也可以有多个 -->
<url-pattern>/son</url-pattern>
<url-pattern>/son/nn</url-pattern>
<url-pattern>/son/*</url-pattern>
<!-- 拦截所有请求 -->
<url-pattern>/*</url-pattern>
<!-- 只会拦截静态资源请求,不会拦截动态资源请求 -->
<url-pattern>/</url-pattern>
<!-- 后缀名拦截 -->
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- 注册Filter -->
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<!-- 设置参数会存到FilterConfig中 -->
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>aaa</filter-name>
<!-- url可以有多种写法,也可以有多个,可参考Servlet,在Filter中'/'不起作用 -->
<url-pattern>/son</url-pattern>
<!-- 表示当前filter拦截指定servlet请求,写了servlet-name就不写url-pattern -->
<servlet-name>aaa</servlet-name>
<!-- 截断的请求类型,可以指定多个
REQUEST: 截断request请求(默认)
FORWORD: 截断forword请求
INCLUDE: 截断include请求
ERROR: 截断<error-page>请求
-->
<dispatcher></dispatcher>
</filter-mapping>
<!-- 注册出现错误时的跳转页面 -->
<error-page>
<!-- 通过错误码配置 -->
<error-code>404</error-code>
<!-- 通过异常类配置 -->
<exception-type>Java.lang.NullException</exception-type>
<!-- 跳转的页面 -->
<location>/servlet</location>
</error-page>
<!-- 注册Servlet监听器 -->
<listener>
<listener-class>类全名</listener-class>
</listener>
</web-app>