There is more than one approach to solving this problem. Like cookies or
sending back a hidden haven to your client. I assume you are using a
connection pool. One trick I use to keep the using from "banging" on the
submit button is to use javascript to disable it after the first time it is
pressed. There will be some on this list that will argue that solution since
not browsers have javasript enabled, however, you can detect for javasript
and if it is not enabled, let the user know they need to do so if they want
to use your web site. (They do it all the time on sites like ETrade and
Ameritrade) Anyway, here is the snippet of code that I use in my servlet to
allow the user to click the submit button once.
Kochanowicz
// JavaScript To prevent user hitting Submit button
too many times.
htmlPage.append("<SCRIPT LANGUAGE=\"JavaScript\"> <!--
Hide script from
old browsers\n ");
htmlPage.append(" var submitted = false;");
htmlPage.append(" function doSubmit(form)");
htmlPage.append(" {");
htmlPage.append(" if (!submitted) {");
htmlPage.append(" submitted = true;");
htmlPage.append(" form.submit();");
htmlPage.append(" }");
htmlPage.append(" }");
htmlPage.append("// End hiding script from old
browsers-->\n</SCRIPT>");
-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Jay
Walters
Sent: Monday, July 30, 2001 1:54 PM
To: [EMAIL PROTECTED]
Subject: Avoiding multiple concurrent requests from same client
I am concerned about a problem and I am sure others have either solved it,
or figured it really isn't a problem for one reason or another.
I have a set of servlets that make use of HttpSession during their
processing. If a single client presses a button on their form twice they
will send two requests to the app server at the same time. Does this cause a
race condition in which servlet thread 2 might write to the HttpSession and
then thread 1, but thread 2 returns the page to the browser so now the data
in HttpSession isn't quite correct (it's the result from thread 1 not thread
2).
The servlet spec seems to say it's up to the developer to cope with this
problem - I need to make sure that the page the user is looking at
corresponds to the state of their session in the app server.
Is this really a problem? Is there a simple or well known way to cope with
this?
Cheers
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html