十、 Web.xml配置
<?xml version="1.0" encoding="GB2312"?>
<!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>图书管理系统</display-name>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<!-- ContextConfigLocation -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context/applicationContext.xml</param-value>
</context-param>
![]()
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>com.sterning.commons.SetCharacterEncodingFilter</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>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,struts.xml,struts_books.xml</param-value>
</init-param>
</filter>
![]()
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
![]()
<!-- Listener contextConfigLocation -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Listener log4jConfigLocation -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
![]()
<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
在Struts 2中,配置有少许改变,最明显的是分发器(dispatcher)已由Servlet转为Servlet Filter, 其配置和Servlet一样简单。和Servlet配置一样,Filter配置中定义了Filter的名称(作为引用)和类名。Filter Mapping通过URI和名称匹配来调用相应的Filter。默认情况下,扩展名为“.action”,这是在default.properties文件(在Struts 2 JAR文件里)的“struts.action.extension”属性定义的。
