Link to home
Start Free TrialLog in
Avatar of dglancy
dglancy

asked on

Preventing multiple HTTP request to a Servlet

My problem is, I have a user which sometimes clicks multiple times on a HTTP link. When they do this it causes multiple requests/threads to be sent to the Servlet. All of these requests are fully processed by the backend.

I know one way of preventing this from happening, i.e. JavaScript, but this is unacceptable for this solution. I also tried setting a parameter in the session and returning from the method when it is set, but this just generates a blank page on the second which arrives before the first has finished.

Any help or suggestions would be greatly appreciated.

Kindest regards,
Damien
Avatar of girionis
girionis
Flag of Greece image

 Thsi article explains how you can avoid duplicate form submissions. You might be able to adapt it for multiple clicks on links.
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Venci75
Venci75

public void doPost(HttpServletRequest req, HttpServletResponse resp) {
    if (req.getSession().getAttribute("processing") != null) {
        req.getSession().setAttribute("processing", new Object());
        try {
            //process the request
        } finally {
            req.getSession().setAttribute("processing", null);
        }
    }
...