Reputation: 6707
I tried a code to insert values. I just noticed after giving add it displays successfully inserted,adds value into the database and if i refresh that page it inserts value again into the database. Why this happens and how to avoid double insertion ?
Upvotes: 1
Views: 1847
Reputation: 8551
If you are required to use submit button, this post will be your help.
How to avoid resubmit in jsp when refresh?
Or you can change your submit button to normal button and when the user click that button, set the action of the form in javascript.
Upvotes: 0
Reputation: 24635
If you do POST request and forward after that, then page refresh will send same form again, because page refresh will refresh your POST request.
If you wan to avoid possibility of refreshing POST request, you have to do redirect after POST request instead.
See wikipedia article for more information:
http://en.wikipedia.org/wiki/Post/Redirect/Get
Upvotes: 2