Prevent Form Duplicate Submit
Scenes
- click
submitbutton multiple times when network delay - refresh page after clicking submit button
- after submit, click
backbutton to back to previous page and submit again
Solutions
There are two points to prevent duplicating form submission: front-end and back-end.
Front-end
Disable submit button via javascript after clicking it.
Back-end
Use session
- create a
tokenon the server-side and save it tosession - send this
tokento the hidden field of form - submit this token together with the form data
- if this token is not the same as server-side’s or there is no token in the session or there is not token in the form, then this is duplicate submit,
- otherwise it is normal submit and clear session’s token.
Struts
In struts, there is token interceptor which can be used to handle multiple form submission problem.
References
Written on August 18, 2019