chrome下面的GET问题

问题描述:在chrome(IE无此问题)下面用GET提交数据,会重复提交两次!(自己在网上找了个spring mvc 下TOKEN的防止重复提交,还是不行,这个方法有问题)。可以看截图,前三个为一组,后两个为一组,都能发现,不管是GET提交,还是POST提交,都会多一个GET提交出来,且他的REFERER为该请求,这太不科学了。

 

 

解决办法:将所有请求都是POST提交,且后台mapping 为method=RequestMethod.POST 。这样第二次的冗余GET请求就会找不到方法,从而无法提交,但是这个冗余的请求还是发出去了,只是无法进入后台,因为前台是GET,后台是POST

 

 

再附一个题外话:防止重复提交的4种方法。PS:spring mvc 封装的没有struts2好啊,token,数据bind 都没有struts2好。

http://technoesis.net/prevent-double-form-submission/

 

Double form submission in a multi-user web based application the most common and critical issue as well. There are many scenarios where we face duplicate submission problem like,

  • Clicking submit button twice.
  • Using Refresh button.
  • Using browser back button traverse back and re-submitting the form.
  • Using browser history feature and re-submit the form.
  • Duplicate HTTP requests from browser.

 

There are several ways to Prevent double form submission

Disable the Submit Button. 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.  A weakness of this is if clients have JavaScript disabled.

My previous post shows a nice way to prevent double form submission using a jQuery plugin.

The Post / Redirect / Get pattern. Send a redirect after submit, this is known as Post-Redirect-Get (PRG) pattern. In short, when the user posts the form, you perform a client side redirect (after consuming the post data) to the response (success) page.

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.

Store a Unique Token in the session. 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 you get a form submission without a valid token, it means that the form has already been submitted and ignore it.

This has the added advantage of adding XSRF protection to your project.

Add Constraint in Database. Change the database to not allow duplicates by adding an unique constraints or creating a unique index. A unique index is an index that requires that each value of the indexed field is unique. This is the most effective solution for preventing double request’s impact.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值