File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Avoiding duplicate form submissions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Avoiding duplicate form submissions" Watch "Avoiding duplicate form submissions" New topic
Author

Avoiding duplicate form submissions

Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
Is there a servlet-based strategy for preventing a user from submitting a form and then hitting refresh over and over again? I guess I should clarify, I don't necessarily need to prevent the user from doing this, but I would like the server to be able to recognize the duplicate submit so that I can handle it. Thanks
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi,

PRG

Hope this helps
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hi Seetharam,

Thanks for the PRG link. However my doubt is as follows :

You talked about submitting the POST request and then redirecting to a view when the request is COMPLETED and then the problem is solved because even if the user hits refresh , its only the view which will be posted again and would not cause a non-idempotent request.

But the above condition has a BIG IF, what IF the ISP provider of the user doing an online transaction is slow and the user gets frustrated and clicks refresh BEFORE completing the initial request. What i mean is, the original request is still in process and user clicks refresh , so a new HTTP POST would be submitted and thereby withdrawing the customers bank account twice. How will PRG pattern be able to stop this ? or is this an another way for doing this ?

Regards
Yogendra N Joshi.


Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Pankaj Misra
Greenhorn

Joined: Dec 28, 2008
Posts: 11
Hi Andy,

The postback functionality that you intend to achieve for avoiding duplicate submission can be achieved by combining the URL method and the request URL verification. The code representation can be found at
http://www.paramountideas.com/node/11

Let me know if it helped you in your case.

Regards
Pankaj
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
That won't help.

Make use of a token in the session scope which you pass in as a hidden input parameter of the form and immediately remove/change it on the very beginning of the request processing.
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hi Bauke,

Can you shred some light on my question too please.

Regards
Yogendra
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
I don't respond to topic hijackers. Start your own topic.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

"misra_pankaj", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pankaj Misra
Greenhorn

Joined: Dec 28, 2008
Posts: 11
Thanks Bear, I have corrected my name as per the site policy
Pankaj Misra
Greenhorn

Joined: Dec 28, 2008
Posts: 11
Andy, please let us know which of the above solutions is more near to solving your problem.

It seems while we discuss and argue about the problem, we may be drifting away from the root cause which may not help.

Andy, please speak up and let us know your thoughts.
Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
I believe this should accomplish what I am looking to do: http://struts.apache.org/2.x/docs/token-interceptor.html
Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
Just wanted to clarify - the real solution to my problem was to use the PRG as Bear outlined in his article. In my previous post I had mentioned using the Struts2 Token Interceptor, but that did not solve the problem I had described in my initial post. The token interceptor solves the problem where the user resubmits during the processing of the previous submit. So the end solution to my initial problem was to redirect from one action to another which in turn changed the url and disallowed users from clicking the refresh button and inserting duplicate records.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Avoiding duplicate form submissions