• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple request due to double click

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In a web page, if customer double click a button (lets say save button) then browser is submitting two request which is causing problem in server side, my code is trying save the data twice for the same user/browser. I know I can have some JavaScript which can disable double click by greying out the button itself, but I am interested in Server side solution.
Any help.
Thanks in advance.
Sam
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sam,
Put a token, such as a randomly generated number, in the session when you display the page. The first time the user clicks save, check the request comes with a matching number and delete the token from the session. The second time the user clicks save, the token will not be in the session and you will know it was a duplicate request.
 
SAM KUMAR
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply.
With "token" I can identify the duplicate request. But I am still confuse about the first request, for ex:
1. User clicks save button.
2. Servlet is saving data.
3. User again clicks Save Button.
4. Using Token, now I can identify that its a duplicate request.
5. But lets say first request is still saving the data, now how do I know then first request has completed saving and 2nd request should redirect to success page.
Thanks.
Sam
 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sam,

I am currently working on solving the same problem. It needs to be done on the server side.

The solution Jeanne suggested is good as we can now catch multiple submits. However, the behavior you described in point 5:


5. But lets say first request is still saving the data, now how do I know then first request has completed saving and 2nd request should redirect to success page.


is the one we are trying to implement in our app.

Check out this link (especially comments section - gives some food for thoughts) : http://www.onjava.com/pub/a/onjava/2003/04/02/multiple_submits.html?page=1

Let's solve it together :-)
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you use JavaScript to disable the button once it has been clicked?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Javascript cannot be relied upon to execute.
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeanne Boyarsky:
Sam,
Put a token, such as a randomly generated number, in the session when you display the page. The first time the user clicks save, check the request comes with a matching number and delete the token from the session. The second time the user clicks save, the token will not be in the session and you will know it was a duplicate request.




I thought of the same thing except a bit differently.

While in the servlet servicing the request:
- check the session for a "transaction" token
- if no token add one to the session and proceed
- else redirect to a "transaction in process" page
- remove transaction token when completed or when there is an exception

I would also use javascript as a complement to minimize redirection to the "transaction in process" page. Let's remember that once the second request is made, the response from the first request become undelivrable.
[ May 13, 2004: Message edited by: Brahim Bakayoko ]
reply
    Bookmark Topic Watch Topic
  • New Topic