• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple request due to double click  RSS feed

 
SAM KUMAR
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • 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 :-)
 
Bosun Bello
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you use JavaScript to disable the button once it has been clicked?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Javascript cannot be relied upon to execute.
 
Brahim Bakayoko
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • 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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!