<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<!-- 容器对于web.xml的加载过程是context-param、listener、filter、servlet-->
<!--filter是过滤器
filter-name 名字
filter-class 类
建立自定义过滤器需要实现javax.servlet.Filter接口,并实现其中init、doFilter、destroy三个方法
filter-mapping 配置所拦截的请求
-->
<!--Spring的字符集过滤器用于处理项目中的乱码问题 -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--context-param该元素用来声明应用范围(整个WEB项目)内的上下文初始化参数
param-name 设定上下文的参数名称。必须是唯一名称
param-value 设定的参数名称的值
加载Spring配置文件
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/MppMContext.xml,
/WEB-INF/classes/springconfig/*.xml
</param-value>
</context-param>
<!-- 创建监听(备注:listener定义的类可以是自定义的类但必须需要继承ServletContextListener) -->
<!-- 加载两个Spring的监听 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- 自定义监听类,加载系统配置文件 -->
<listener>
<listener-class>com.china.init.MyListener</listener-class>
</listener>
<!-- 配置Struts2的核心Filter -->
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- 配置Struts2拦截的请求 /* 表示所有请求 -->
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>*.action</url-pattern>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<!-- 配置错误页面 -->
<error-page>
<error-code>500</error-code>
<location>/pages/login/error.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/pages/login/error.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/pages/login/error.jsp</location>
</error-page>
<!-- 配置Web应用的首页列表 -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>