Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

refresh submit the form again

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my application, I am adding form data in database on click of submit button (method is get)...

But the problem is, when user refreshes the page, the data added one more time into the database and so on...

What can be the solution for this, please some body give me good link for this problem...

Thanks a lot.
[ December 28, 2005: Message edited by: Bear Bibeault ]
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To avoid registering the same information twice,
you could check that's it not already registered, using another SQL query.


How??

Thanks.

And suppose user feels the same information again and submit...
 
Balaji Venkat
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
GET method is Idempotent and POST is not.

In case of GET, the data will be sent in the URL as query string. That's why, the data is stored in the database again & again, on refresh.

To avoid the problem, you can use POST method to send data.

Regards
Balaji
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But the problem is, when user refreshes the page, the data added one more time into the database and so on...


What you are talking is called Double Submit Problem. Check PGR Pattern
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Balaji Venkat:
Hi,
GET method is Idempotent and POST is not.

In case of GET, the data will be sent in the URL as query string. That's why, the data is stored in the database again & again, on refresh.

To avoid the problem, you can use POST method to send data.

Regards
Balaji


I tried with post method also. In case of post method, the only difference I felt is, browser ask user to send information again or cancel the refresh action.... but if user click on retry then the same thing happens...

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a big fan of the PRG pattern linked above. That's a very good article about it. It avoids the browser warning that it must resubmit to display a page, avoids accidental duplicate updates, allows bookmarking, and comes closer to the REST architecture definitions of GET and POST. It's all good.
 
A Babu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi rathi,
what happend to your problem.Your problem solved or not.Please tell me ,i have also same problem.

cheers,
babu.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also consider the Synchronizer Token design pattern. It is a general solution to avoid duplicated submission. Essentially, you just create a new unique token for the form as a hidden field. And your form processing servlet check to ensure the submitted token is the one your are expecting. Check the book Core J2EE Patterns for details.
 
Mohan Reddy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi rathi

R u displaying any resultant page after submitting the values??

If you are displaying the result in other page, it leads to the problem. Do one thing , submit the values and redirect the result to result page. Even u refresh the page the data wont be submitted. Only result page will be refreshed. I had the same problem before, but got out of it.

Try this once.

mohun:-)

Always do what you are afraid to do..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohan Reddy, JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

Please read this for more information.

thanks,
bear
JavaRanch Sheriff
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic