struts2中token防止重复提交表单

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>

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

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

http://fanshuyao.iteye.com/

猜你喜欢

转载自fanshuyao.iteye.com/blog/2226631
今日推荐