When i click a link im calling a servlet. When i click that link multiple time the servlet throws an error (error details not important) Though there are other work around for this fix (Like disable the link once clicked, etc) I am curious is there any way to control this thru request/response Object.
the error is relevant, having multiple calls to a servlet acting different then one means you have thread safety issues probably due to the way you implemented the servlet
The details of the servlet's error are potentially interesting. The servlet APIs in general should not be throwing errors, my guess is that this is an application error of some kind.
The general principle I try to apply is:
1). We construct the UI to make it difficlut for the user to inadvertantly submit the same request twice (eg. debit my account £100, really don't want to send two such requests. This is where some nift javascript can help.
2). We construct the application to defend against inadvertant double requests, for example by including some kind of identifier on the requests that allow is to spot duplicates.
We do not assume that the UI is perfect, our business application layer has final responsibility for preventing double actions.
Set a flag in the servlet session scope when entering the servlet and reset it when leaving. If the flag is set when entering, then silently ignore.
You will need error handling in your servlet so a ServletException does not leave the flag set.
The error is really, really relevant.
You could have thread safety issues but you can also have a "race-condition", that is, the result of the process depends on the execution order, one of them could give you an error.
(race condition : http://en.wikipedia.org/wiki/Race%5Fcondition)