• Post Reply Bookmark Topic Watch Topic
  • New Topic

F5 causes action to be executed again  RSS feed

 
Kevin Stembridge
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
I'm working on a Struts-based web application that's giving me a bit of grief when the page is refreshed.
For certain actions the user can perform, records are inserted into a database. If the user then refreshes the page, the same action gets performed and another record gets inserted.
How can I ensure that, after submitting an action, the page is not left in a state where the same action will be executed again by refreshing the screen?
Cheers,
Kevin
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are lots of solutions to this. One way is to generate a key that goes along with the form data. The key is added to some map when the form is created. When the user clicks once the key is removed from the map. If the user clicks again, you check if the key exists and because it doesn't you don't handle the command.
You could also use a redirect when you return the next view after you handle the form submission. (I think you can do that with Struts.) I don't think there any "out of the box" solutions to this. But hopefully these ideas will get you started on your own solution.
 
Kevin Stembridge
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nathaniel,
I followed your second suggestion and made a call to response.sendRedirect() just before returning from the Struts Action class.
Worked a treat
Thanks very much.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Struts and Other Frameworks Forum...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!