<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<!--spring的监听器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- context-param 元素用来设定web站台的环境参数(context)-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/itheima11/gyl/spring/applicationContext.xml</param-value>
</context-param>
<!--struts2过滤器-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--欢迎页面设置-->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
1. spring与容器整合: 使用listener
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- context-param 元素用来设定web站台的环境参数(context)-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/itheima11/gyl/spring/applicationContext.xml</param-value>
</context-param>
2. 若要添加自定义过滤器:
<!-- 自定义过滤器,要放置到struts2的过滤器的上面 -->
<filter>
<filter-name>SystemFilter</filter-name>
<filter-class>cn.itcast.elec.util.SystemFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SystemFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.do</url-pattern>
</filter-mapping>
3. struts2与容器的整合是通过过滤器整合的
<!-- 添加struts2的过滤器,这是struts2执行的核心 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.do</url-pattern>
</filter-mapping>
4. springMVC与容器的整合: 用serverlet
<servlet>
<servlet-name>springMvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--springMVC配置文件-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/ApplicationContext-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>