requestdispatcher forward adds again if i give refresh
I tried a code to insert values. I just noticed after giving add it displays successful开发者_Go百科ly 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 ?
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
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.
精彩评论