struts2防重复提交

1.页面

需要在页面上加<s:token></s:token>,页面示例如下:

<s:actionerror/><s:actionmessage/>
<s:form action="reg!register.do">
    用户名<input name="name"/><s:fielderror><s:param>name</s:param></s:fielderror><br/>
    密码<input name="password"/><s:fielderror><s:param>password</s:param></s:fielderror><br/>
    <s:submit value="注册"/>
    <s:token></s:token>
</s:form>

 

2.struts.xml

<constant name="struts.action.extension" value="do"/>
<constant name="struts.objectFactory" value="spring"/>
<constant name="struts.custom.i18n.resources" value="conf.ApplicationResources"/>
<!-- 开启动态方法调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<action name="reg*" class="registerAction">
    <interceptor-ref name="defaultStack"/>
    <interceptor-ref name="token"> <param name="includeMethods">register</param> </interceptor-ref>
    <result name="register">/WEB-INF/page/profile/register.jsp</result>
    <result name="fail">/WEB-INF/page/profile/fail.jsp</result>
    <result name="invalid.token">/WEB-INF/page/profile/register.jsp</result>
</action>

 

3.ApplicationResources.properties(在src的conf目录下)

struts.messages.invalid.token = \u8bf7\u4e0d\u8981\u91cd\u590d\u63d0\u4ea4\u8868\u5355 (中文:请不要重复提交表单)

 

 

你可能感兴趣的:(struts2防重复提交)