aspose file tools*
The moose likes Servlets and the fly likes refresh submit the form again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "refresh submit the form again" Watch "refresh submit the form again" New topic
Author

refresh submit the form again

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Dec 27, 2005
Posts: 1
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

Joined: Nov 15, 2004
Posts: 1026

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


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Jan 29, 2003
Posts: 8791
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 good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
A Babu
Ranch Hand

Joined: Nov 28, 2005
Posts: 114
hi rathi,
what happend to your problem.Your problem solved or not.Please tell me ,i have also same problem.

cheers,
babu.


Thanks,
www.Admakr.in
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
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

Joined: Feb 10, 2006
Posts: 21
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..


cheers<br /> <br />mohan.<br /> <br /><br />Always do what you are afraid to do...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: refresh submit the form again