• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

form submission

 
Sujit Nene
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I have a problem when submitting a form. Say, I submit a form to a servlet from a jsp page. From servlet I am forwarding the request to another page. after getting the forwarded page, if i refresh that page, the form on the previous page is again gets submitted. This results into an erroneous record insertion into databse. How can i avoid this scenario?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sujit Nene:
[Refreshing the page displayed after form submission] This results into an erroneous record insertion into databse. How can i avoid this scenario?

You could change the forward into a redirect, I guess. Or you can do what I've seen some sites do, warn your users not to refresh the page.
But those are all bad solutions. What you need to do is detect duplicates and prevent them from entering the database. This is really easy - for instance, you could stick a timestamp (System.currentTimeMillis()) in a hidden field of your form, store it in your database record, and for good measure impose a uniqueness constraint on (user, timestamp) at the database level even if you detect duplicates in your application. That is your absolute guarantee that duplicate submissions will never make it into the database.
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic