1

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 ?

2 Answers 2

2

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.