• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

refresh submit the form again

 
Ranch Hand
Posts: 3850
  • 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: 3850
  • 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...
 
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
 
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: 3850
  • 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...

 
(instanceof Sidekick)
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.
 
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.
 
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.
 
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..
 
Marshal
Posts: 67340
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!