struts2.xml配备要点(验证基于方法级)
struts2.xml配置要点(验证基于方法级)xml 代码?!DOCTYPE?struts?PUBLIC?-//Apache?Software?Foundation/
struts2.xml配置要点(验证基于方法级)
xml 代码?
- <!DOCTYPE?struts?PUBLIC?"-//Apache?Software?Foundation//DTD?Struts?Configuration?2.0//EN"??"http://struts.apache.org/dtds/struts-2.0.dtd">????
- <struts>????
- ??
- <include?file="struts-default.xml"?/>????
- <!--前几天有人说继承不成功,有贴回复是<package>和<include>顺序问题(<include/>和<package>没先后顺序),关键在于解析是自上而下的,要继承某xml文件,就要先引入该文件-->??
- <package?name="default"?extends="struts-default">??
- ??
- <!--定义默认视图,我定义默认为freemarker-->??
- <result-types>????
- ??<result-type?name="freemarker"?class="org.apache.struts2.views.freemarker.FreemarkerResult"?default="true"?/>????
- </result-types>??
- ??
- <!--如果你仅仅需要页面跳转,就没必要在写一个action了,直接用ActionSupport就行了-->??
- <action?name="login"?class="com.opensymphony.xwork2.ActionSupport">??
- <!--默认返回success,我上面定义默认type为freemarker,这里就不用定义type属性了-->??
- ??<result>/Login.ftl</result>??
- </action>????
- <action?name="userInput"?class="pro.action.app.UserRegisterAction">????
- ??<interceptor-ref?name="createSession">????
- ??<!--经测试,该拦截器没有该参数,设置后会抛异常;该参数主要设置该拦截器作用于那些方法-->??
- ????<!--<param?name="includeMethods">input,back,cancel</param>-->????
- ??</interceptor-ref>????
- ??<interceptor-ref?name="token">??
- ????<param?name="excludeMethods">input,back,cancel</param>????
- ??</interceptor-ref>????
- ??<interceptor-ref?name="model-driven"?/>????
- ??<interceptor-ref?name="validationWorkflowStack">??
- ????<!--设置不需拦截的方法-->???
- ????<param?name="validation.excludeMethods">input,back,cancel</param>????
- ????<param?name="workflow.excludeMethods">input,back,cancel</param>????
- ??</interceptor-ref>????
- ??<result?name="invalid.token">/doubleSubmit.html</result>????
- ??<result?name="input">/app/UserRegister.ftl</result>????
- ??<result?name="login">/Login.ftl</result>????
- ??<result?name="success">/Login.ftl</result>????
- </action>??
- <!--注意你也可以给action设置参数,同样是用<param/>赋值-->??
- </package>????
- <include?file="cfg/struts/struts-filedownload.xml"></include>??
- </struts>????