Struts2.1的使用配置

Struts2.1的应用配置

Struts2.1的应用配置:
一、加入版本一致的.jar包:
下载的struts-2.1.6-all.zip解压包中lib目录中的:
(1)struts2-spring-plugin-2.1.6.jar(2)commons-logging.jar(3)freemarker.jar(4)ognl.jar(5)
struts2-core.jar(6)xwork.jar(7)commons-io-1.3.2.jar(8)commons-fileupload-1.2.1.jar
(9)struts2-dojo-plugin-2.1.6.jar(10)struts-dwr-plugin-2.1.6.jar(11)spring-web-2.5.3.jar
(注 意lib目录中Struts2框架的类库有版本后缀,例如commons-logging.jar可能为:commons-logging- 1.0.4.jar,struts2-core.jar可能为struts2-core-2.1.6.jar)将上述的包加入到项目的WEB- INF\lib目录中,这里需要确保这些包的版本一致。
二、打开WebRoot\WEB-INF目录中的web.xml文件
加入web的过滤器和mapping。
   <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>
三、创建strut2的配置文件,在src下创建struts.xml配置文件:
<struts>
<include file="struts-default.xml" />
    <package name="Spring" extends="struts-default">
        <action name="UserActionLogs" class="com.bsp.action.UserAction">
            <result name="success">/index.jsp</result>
            <result name="error">/sshlogin.jsp</result>
             <result name="input">/userlogin.jsp</result>
        </action>
    </package>
</struts>
还要在src下创建struts.properties属性文件:
#指定Struts 2处于开发状态
struts.devMode = true
#指定当Struts 2配置文件改变后,Web框架是否重新加载Struts 2配置文件
 struts.configuration.xml.reload=true
#设置字符集
struts.i18n.encoding=UTF-8
#该属性指定Http的请求后缀
struts.action.extension=do,action  
#指定当前应用默认的国际化地区信息
#struts.locale=en_us
struts.custom.i18n.resources=globalMessages
struts.objectFactory =spring
四、struts的应用开发,编码。