您的位置:首页 > 编程语言 > Java开发

struts2中token防止重复提交表单

2016-04-18 16:39 591 查看

struts2中token防止重复提交表单

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

蕃薯耀 2015年7月12日 11:52:32 星期日

http://fanshuyao.iteye.com/

第一步:在表单中加上<s:token></s:token>标签,这个需要在页面头引入struts的标签

<%@ taglib prefix="s" uri="/struts-tags" %>

例:

<s:form action="login" method="post" theme="simple">
用户名:<s:textfield name="userName"></s:textfield><br/>
密码:<s:password name="userPassword"></s:password><br/>

<s:token></s:token>
<input type="submit" value="登录" /><br/>
</s:form>


第二步:在struts.xml文件中配置token,即配置重复提交跳转的页面及拦截器

<result name="invalid.token">token.jsp</result>
<interceptor-ref name="token"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>

例:

<package name="strutsTest" extends="struts-default">
<action name="login" class="com.struts2.action.LoginAction">
<result name="success">userIndex.jsp</result>
<result name="input">login.jsp</result>
<result name="invalid.token">token.jsp</result>
<interceptor-ref name="token"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
</package>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: