8防止重复提交
来源:互联网 发布:sai for mac 10.12 编辑:程序博客网 时间:2024/06/06 00:09
struts2防止重复提交
Struts2中防止重复提交需要在<action >...</action>中增加下面的配置:
//使用系统的token拦截器
<interceptor-ref name="token"/>
//使用系统的默认拦截器
<interceptor-ref name="defaultStack"/>
//如果是重复提交需要转向的页面
<result name="invalid.token" >/error_chongfu.jsp</result>
例如:
<action name="testAdd" class="testAction" method="testAdd">
<interceptor-ref name="token"/>
<interceptor-ref name="defaultStack"/>
<result name="invalid.token" >/error.jsp</result>
<result name="success">/index.jsp</result>
<result name="error">/error.jsp</result>
</action>
然后再JSP导入struts2的标签库:<%@taglib prefix="s" uri="/struts-tags"%>,并在<form>...</form>中放置<s:token />。
其中<s:token />标签用来生成一个唯一的隐藏token标识并将此标识放到session中,在运行的时候生成的内容如下:
<input type="hidden" name="struts.token" value="C21ZWHEH0Q4B6FY15ZO5BFM1I9W8SIQH" />
例如:
<%@page contentType="text/html; charset=utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<form id="productForm" method="post" action="${ctx }/testAdd.action">
请输入用户名称:<input type="text" name="roleName" value="mmmmm">
<s:token />
<input type="submit" value="提交">
</form>
</html>
这样当我们提交表单时就会有struts2的token拦截器拦截,token拦截器将会话token与请求token比较,如果重复提交则返回invalid.token结果并转到相应的页面。
Struts2中防止重复提交需要在<action >...</action>中增加下面的配置:
//使用系统的token拦截器
<interceptor-ref name="token"/>
//使用系统的默认拦截器
<interceptor-ref name="defaultStack"/>
//如果是重复提交需要转向的页面
<result name="invalid.token" >/error_chongfu.jsp</result>
例如:
<action name="testAdd" class="testAction" method="testAdd">
<interceptor-ref name="token"/>
<interceptor-ref name="defaultStack"/>
<result name="invalid.token" >/error.jsp</result>
<result name="success">/index.jsp</result>
<result name="error">/error.jsp</result>
</action>
然后再JSP导入struts2的标签库:<%@taglib prefix="s" uri="/struts-tags"%>,并在<form>...</form>中放置<s:token />。
其中<s:token />标签用来生成一个唯一的隐藏token标识并将此标识放到session中,在运行的时候生成的内容如下:
<input type="hidden" name="struts.token" value="C21ZWHEH0Q4B6FY15ZO5BFM1I9W8SIQH" />
例如:
<%@page contentType="text/html; charset=utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<form id="productForm" method="post" action="${ctx }/testAdd.action">
请输入用户名称:<input type="text" name="roleName" value="mmmmm">
<s:token />
<input type="submit" value="提交">
</form>
</html>
这样当我们提交表单时就会有struts2的token拦截器拦截,token拦截器将会话token与请求token比较,如果重复提交则返回invalid.token结果并转到相应的页面。
0 0
- 8防止重复提交
- 防止重复提交数据
- 防止重复提交
- struts防止重复提交
- 防止表单重复提交
- 防止重复提交
- 防止重复提交表单
- javascript 防止重复提交
- Struts防止重复提交
- 防止struts重复提交
- 防止重复提交
- javascript 防止重复提交
- Struts2 防止重复提交
- 防止重复提交
- 防止servlet重复提交
- 防止重复提交
- Webwork防止重复提交
- 防止button重复提交
- java基础八:字符串
- VirtualBox迁移虚拟机和磁盘VDI
- absolute与margin实现完全居中布局(IE8+)
- 半透明窗口中显示标准控件(控件与文字不透明)的实现方案(附源码)
- 日志
- 8防止重复提交
- NIO(一)
- NavigationController 设置导航栏主题
- Java 之 Date 获取 年月日时分秒
- 防攻击进行sha加密
- 9web xml元素
- Android动画原理分析
- webservice学习之处理Map等CXF无法自动转化的类型
- 提高项目31.1-统计代码中的if、while、 for字符串