1.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<s:form action="userAction" name="" method="post" >
<div>
用户名:<s:textfield name="uname"></s:textfield>
</div>
<div>
密码:<s:password name="upwd" ></s:password>
</div>
<div>
性别:<s:radio list="#{1:'男',2:'女'}" name="sex"></s:radio>
</div>
<div>
爱好:
<s:checkboxlist list="#{1:'看美女',2:'吃饭',3:'睡觉',4:'睡觉'}" name="hobby"></s:checkboxlist>
</div>
<div>
城市:
<s:select list="#{'看美女':'看美女','吃饭':'吃饭','睡觉':'睡觉','睡觉':'睡觉'}" name="city"></s:select>
</div>
<div>
介绍:
<s:textarea name="intro" cols="30" rows="5"></s:textarea>
</div>
<div>
靓照:
<s:file name="img"></s:file>
</div>
<div>
<s:submit value=" 提 交 "></s:submit>
<s:reset value=" 重 置 "></s:reset>
</div>
<s:token></s:token><%-- 防止表单重复提交,这句话很重要--%>
</s:form>
</body>
</html>
2.struts.xml配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.ui.theme" value="simple"></constant>
<package name="test" namespace="" extends="struts-default">
<interceptors>
<interceptor-stack name="myinterstack">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="token"></interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="userAction" class="com.action.UserAction">
<interceptor-ref name="myinterstack"></interceptor-ref>
<result name="success">/success.jsp</result>
<result name="invalid.token">/index.jsp</result><!-- 这里invalid.token的意思是当表单重复提交之后 -->
</action>
</package>
</struts>
相关推荐
struts2防止表单重复提交,利用struts的拦截器tokenSession,轻轻松松解决表单重复提交的问题。 附件为源代码,后台延迟了3秒,可直接在web服务器下部署运行,输入用户名和密码后,多点几次提交按钮,然后看控制台...
详解struts2的token机制和cookie来防止表单重复提交 今天在做一个投票系统时要实现防止表单重复提交! 当时就想到了用struts2提供的token机制 struts2的token机制防止表单重复提交: 首先需要在提交的jsp页面(要...
struts token机制解决表单重复提交
这里是Struts2 中放置表单重复提交的例子。
详细介绍struts+token机制解决表单重复提交问题。附带相关代码
主要讲解了在structs怎样通过Token令牌解决表单重复提交的问题。附带了擦参考项目。
防止表单重复提交 token eclipse项目
struts2中token限制表单多次提交
这个示例简单易懂,就是利用token过滤器
NULL 博文链接:https://eleopard.iteye.com/blog/1766851
token标签:防用户多次提交表单。 textarea标签:文本域。 updownselct标签:支持选项内容的上下移动。 password表单:密码表单域。 textfield标签:单行文本输入框。 非表单标签: actionerror标签:输出...
很好的大家试试吧 看看怎么样
token标签:防用户多次提交表单。 textarea标签:文本域。 updownselct标签:支持选项内容的上下移动。 password表单:密码表单域。 textfield标签:单行文本输入框。 非表单标签: actionerror标签:输出...
15.3 使用令牌防止表单重复提交 313 15.3.1 使用s:token/表单标签 313 15.3.2 令牌拦截器规则的例外 314 15.4 自动显示等待页面 316 15.5 完成CRUD操作的一个动作 317 15.5.1 CRUD 317 15.5.2 拦截器和接口 318 ...
简单使用struts2,Hibernate 3实现注册模块 另外使用token方式防止表单重复提交 使用hbm2ddl.auto,透过pojo产生数据库表
第15章防止重复提交 252 15.1 标记管理 252 15.2 使用Token拦截器 253 15.3 使用Token Session拦截器 256 15.4 小结 257 第16章调试与性能分析 258 16.1 debug标签 258 16.2 Debugging拦截器 259 16.3 性能...
本书内容非常全面,涵盖了众多书籍所有知识要点,并结合作者自己经验总结而编写,内容相当丰富,是查找技术的好帮手及学习Struts2的不二选择 众所周知,一般书籍为了销售需要,往往很少的知识点,却需要添加大量的...