How do you prevent a user from posting data multip

2019-01-22 08:20发布

I am working on a web application (J2EE) and I would like to know the options that are available for handling a double post from the browser.

The solutions that I have seen and used in the past are all client-side:

  • Disable the submit button as soon as the user clicks it.
  • Follow a POST-Redirect-GET pattern to prevent POSTs when the user clicks the back button.
  • Handle the onSubmit event of the form and keep track of the submission status with JavaScript.

I would prefer to implement a server side solution if possible. Are there any better approaches than the ones I have mentioned above, or are client-side solutions best?

7条回答
▲ chillily
2楼-- · 2019-01-22 09:19

I'd use a timestamp and compare values with your server side code. If two timestamps are close enough and have the same IP address, ignore the second form submission.

查看更多
登录 后发表回答