Multiple inserts on refresh
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sheetal_Phatak
Posted On:   Thursday, August 7, 2003 01:41 AM

Hi



I have screen which add user information and goes to a JSP page using tiles. So when it comes to this jsp page the url in the address bar of explorer is saveUser.do . Now when I hit the refresh button it again adds the user information. How to avoid this. My user id is being auto generated. So there is no way to keep track of user id and seeif it already exists. But I can add multiple users for the logged in user. So I cannot check if user already exist for the logged in user.



Can anyone help?? The request.getRequestURL also returns the same above url.



$heetal

Re: Multiple inserts on refresh

Posted By:   Steve_Leach  
Posted On:   Thursday, August 7, 2003 09:36 AM

After you have added the data to the database, you should redirect (not forward) the client to another page that just displays the data. UserForm.jsp posts to UserPost.jsp which adds the data to the database and then calls response.redirect() to sent the user to UserView.jsp. UserPost.jsp should not write any output to the response.


If you can't find out which record has just been added, UserView.jsp could just list the last 10 inserts or something, or maybe even just say "thank you for your input".


What database are you using ? MySQL, for example, allows you to do "SELECT last_insert_id()" to get the autoincrement ID of the last record inserted, and you can then use that to display the inserted data in UserView.jsp.


Hope this helps.

About | Sitemap | Contact