Sumithra
Sumithra

Reputation: 6707

requestdispatcher forward adds again if i give refresh

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

Answers (2)

zawhtut
zawhtut

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

newbie
newbie

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

Related Questions