Struts2的常用配置 <!-- -----------------web.xml的配置------------------- --> <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" 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_5.xsd"> <!-------------- 初始化的清除操作 ----------------> <filter> <filter-name>struts2CleanUpFilter</filter-name> <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class> </filter> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <!--<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> struts2.1.4以前的版本--> <init-param> <param-name>struts.il8n.encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2CleanUpFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- ------------------struts.xml的配置(src文件夹下)---------- ---- --> <?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="" value=""/> <!-- --> <constant name="struts.il8n.encoding" value="utf-8"/> <!--编码设置 --> <constant name="struts.action.extension" value="do,action"/> <!--请求后缀设置 --> <constant name="struts.server.static.browserCache" value="false"/> <!--开发阶段关闭静态缓存 --> <constant name="struts.configuration.xml.reload" value="true"/> <!--开发阶段,每次重新读取struts.xml文件 --> <constant name="struts.devMode" value="true"/> <!--开发阶段开启错误信息打印功能 --> <constant name="struts.enable.SlashesInActionNames" value="true"/> <!--在Action的name属性中使用“/” --> <constant name="struts.ognl.allowStaticMethodAccess" value="true"/> <!--使用ognl表达式访问静态方法 --> <constant name="" value=""/> <!-- --> <!-- Interceptor的配置 --> <package name="loginAndRegist" extends="struts-default" namespace="ssj" > <interceptors> <interceptor name="userRightInter" class="com.ssj.UserRightInter" > <param name="excludeMethods">login</param> <!----> <param name="includeMethods">regist</param> <!----> </interceptor> <interceptor-stack name="userRightInterStack"> <interceptor-ref name="userRightInter" /> <interceptor-ref name="defaultStack" /> </interceptor-stack> </interceptors> </package> <!-- --> <!-- Action的配置 --> <!-- --> <!-- result type:chain、dispatcher、redirect、redireAction、stream--> <!-- param name:location、actionName、namespace --> <package name="" extends="" namespace=""> <action name="" class="" method=""> <interceptor-ref name="" /> <result name="" type="" > <param name="" /> </result> </action> </package> <!------- 示例:转入下一action --------> <package name="loginAndRegist" extends="struts-default" namespace="ssj"> <action name="login" class="com.ssj.loginAndRegist" method="regist"> <interceptor-ref name="checkUser" /> <result name="success" type="chain" > <param name="actionName" >/cxd/login.action</param> </result> </action> </package> <!------- 示例:动态方法调用(1)使用method属性 --------> <package name="userManage" extends="struts-default" namespace="ssj"> <action name="*UserAction" class="com.ssj.UserAction" method="{1}User"> <!-- <a href="<%=path %>/ssj/deleteUserAction.action?userID=${User.userID}"></a> --> <result name="success" type="chain" >/user/{1}User.jsp</result> </action> </package> <!------- 示例:动态方法调用(2)不使用method属性 --------> <package name="userManage" extends="struts-default" namespace="ssj"> <action name="UserAction" class="com.ssj.UserAction" > <!-- <a href="<%=path %>/ssj/UserAction!deleteUser.action?userID=${User.userID}"></a> --> <result name="success" type="chain" >success.jsp</result> </action> </package> </struts> <!-- ------------------struts.properties的配置(在/WEB-INF/classes文件夹下)-------- --> struts.il8n.encoding=utf-8
struts2 基本jar包