开发者

requestdispatcher forward adds again if i give refresh

开发者 https://www.devze.com 2023-02-03 03:58 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消