1.Use JavaScript to disable the button a few ms after click. This will avoid multiple submits being caused by impatient users clicking multiple times on the button.
2.Send a redirect after submit, this is known as Post-Redirect-Get (PRG) pattern. This will avoid multiple submits being caused by users pressing F5 on the result page and ignoring the browser warning that the data will be resend, or navigating back and forth by browser back/forward buttons and ignoring the same warning.
3.Generate an unique token when the page is requested and put in both the session scope and as hidden field of the form. During processing, check if the token is there and then remove it immediately from the session and continue processing. If the token is not there, then block processing. This will avoid the aforementioned kinds of problems.
In Spring you can use RedirectView as implementation of the PRG pattern (as described in point 2). The other two points needs to be implemented yourself.
发布评论
评论(11)
....既然知道struts就可以模仿struts,这个和框架其实没关系。
原理:在session里保存一份 token,每次提交刷新下session里的token.
例如,每次请求A.JSP ,动态生成个session值,然后按submit时,
1,检查session里的 token(如果session已经相等,说明是重复提交,不做任何处理)
2,如果session不存在 token或者 token不相等,那么判断为非重复提交
当然此种方法还可以和JS同时使用,加强用户体验,比如每次提交,提交按钮变成灰色
没有session怎么弄,用户根本就不用登录
返回视图时加上redirect:视图名称
返回视图时加上redirect:视图名称
这也是一种解决办法
我都是提交后redirect一下
谢谢回答
我现在也是这么干的
1.Use JavaScript to disable the button a few ms after click. This will avoid multiple submits being caused by impatient users clicking multiple times on the button.
2.Send a redirect after submit, this is known as Post-Redirect-Get (PRG) pattern. This will avoid multiple submits being caused by users pressing F5 on the result page and ignoring the browser warning that the data will be resend, or navigating back and forth by browser back/forward buttons and ignoring the same warning.
3.Generate an unique token when the page is requested and put in both the session scope and as hidden field of the form. During processing, check if the token is there and then remove it immediately from the session and continue processing. If the token is not there, then block processing. This will avoid the aforementioned kinds of problems.
In Spring you can use RedirectView as implementation of the PRG pattern (as described in point 2). The other two points needs to be implemented yourself.
完全没帮助
SpringMVC用同一个URL对应不同请求方法,比如你输入地址,回车单击,发送的是GET请求,这时界面上看到的是请求界面。当你在表单里面填好值,点击页面的提交按钮,同样一个URL会作为POST请求提交,两个对应在SpringMVC的Controller里面的处理方法不同的。
至于像Struts2里面的token防止重复提交,这更应该是开发者自己考虑的吧。