Welcome 微信登录

首页 / 软件开发 / JAVA / 米子SSH之路(二) SSH的配置 (2) 集成Struts2

米子SSH之路(二) SSH的配置 (2) 集成Struts22011-11-02 BlogJava 米子上一篇已经讲了Spring2.5的配置,这章讲的就是怎么在Spring2.5上集成Struts.

三,在Spring2.5 集成 Struts2

3.1 修改现有的web.xml .

加上下面两段代码:

<filter>          <filter-name>struts2</filter-name>          <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>   </filter><filter-mapping>          <filter-name>struts2</filter-name>          <url-pattern>/*</url-pattern>      </filter-mapping>
3.2 完整的web.xml代码

<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">    <!-- ###################################### -->    <!-- ##########  Struts2  ################## -->    <!-- ###################################### -->    <!--      * Struts2的主要的Filter,负责四个方面的功能:     * (1)执行Actions     * (2)清除ActionContext     * (3)维护静态内容     * (4)清除request生命周期内的XWork的interceptors     * 另注:该过滤器应该过滤所有的请求URL。一般被设置为/*     ************ -->    <filter>          <filter-name>struts2</filter-name>          <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>      </filter>    <!-- ###################################### -->    <!-- ##########  Spring2  ################## -->    <!-- ###################################### -->    <!--      * [ <context-param></context-param ] =>用来设定web站台的环境参数     * [ <param-name></param-name> ]  (子元素)=> 用来指定参数的名称     * [ <param-value></param-value> ] (子元素)=> 用来设定参数值     * ************     * 从类路径下加载spring的配置文件, 多个配置文件可以用逗号和空格区分     * classpath:  关键字特指类路径下加载     ******************** -->    <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>classpath:applicationContext*.xml</param-value>    </context-param>    <!--      * [<listener></listener>]=>用来设定监听接口     * [<listener-class></listener-class>](子元素)=>定义Listener的类名称     * *******     * 负责启动spring的监听器     * 它将引用处的上下文参数获得spring配置文件地址     * 指定Spring提供的ContextLoaderListener Web 容器监听器,     * 该监听器在web容器启动时自动运行并且根据ContextLoaderListener参数     * 获取Spring配置文件,并启动Spring容器。     ************** -->    <listener>        <listener-class>            org.springframework.web.context.ContextLoaderListener        </listener-class>    </listener>    <filter-mapping>          <filter-name>struts2</filter-name>          <url-pattern>/*</url-pattern>      </filter-mapping>      <display-name>miziStudy</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></web-app>