struts2.2.3使用总结

需要的jar
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang-2.5.jar
freemarker-2.3.16.jar
javassist-3.12.0.GA.jar
ognl-3.0.1.jar
struts2-core-2.2.3.jar
struts2-spring-plugin-2.2.3.jar
xwork-core-2.2.3.jar

struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <!--
        <constant name="struts.enable.DynamicMethodInvocation" value="false"
        /> <constant name="struts.devMode" value="false" /> <package
        name="default" namespace="/" extends="struts-default">

        <default-action-ref name="index" /> <global-results> <result
        name="error">/error.jsp</result> </global-results>

        <global-exception-mappings> <exception-mapping
        exception="java.lang.Exception" result="error"/>
        </global-exception-mappings> <action name="index"> <result
        type="redirectAction"> <param name="actionName">HelloWorld</param>
        <param name="namespace">/example</param> </result> </action>
        </package> <include file="example.xml"/>
    -->

    <package name="registration" namespace="/" extends="struts-default">
        <action name="u" class="u">
            <result name="success">/registerSuccess.jsp</result>
            <result name="fail">/registerFail.jsp</result>
            <result name="list">/userlist.jsp</result>
            <result name="load">/user.jsp</result>
        </action>
    </package>

</struts>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


    <display-name>User registration</display-name>
    
    
    <!-- 把session的关闭延迟到jsp页面显示之后,在配在struts2上面。 -->
    <filter>
        <filter-name>OpenSessionInView</filter-name>
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>OpenSessionInView</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    
    
    <!-- 使用spring过滤器解决中文乱码问题 -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>GBK</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>    
    </filter-mapping>
    
    
    
    <!-- 使用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>
    
    
    <!-- spring 与 struts2 整合时需要的配置 ,实现在action中依赖注入功能-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
<!--        <param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>-->
        <param-value>classpath:beans.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    

</web-app>


你可能感兴趣的:(struts2.2)