struts2中防止多次提交表单的token标签

来源:互联网 发布:expect详解sql 编辑:程序博客网 时间:2024/05/17 03:25

                        token标签用于防治多次提交的标签。如果需要该标签起作用,则应该在Struts2的配置文件中启用

TokenInterceptor拦截器后TokenSessionStoreInterceptor拦截器。token标签的实现原理是在表单中拉架一个隐

藏域,每次加载该网页时,该隐藏域的值double不相同。而TokenInterceptor拦截器则拦截所有的用户请求,如果

两次请求时该隐藏域的值相同,则组织表单的提交。如下:

<%@ page contentType="text/html; charset=GBK" language="java"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
   <head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title>使用s:token防止重复提交</title>
<s:head />
   </head>
<body>
    <h3>使用s:token防止重复提交</h3>
<s:form>
<s:token />
</s:form>
</body>
</html>
访问后产生的HTML页面的源代码:
<form id="12-17" name="12-17" action="/struts2Tags/12-17.jsp" method="post">
     <table class="wwFormTable">
       <input type="hidden" name="struts.token.name" value="struts.token" />
       <input type="hidden" name="struts.token" value="91J81D0AZGKCG54YCS0QN8XMRVQW3UMJ" />
     </table>
</form>
1 0
原创粉丝点击