File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Prevent multiple submit... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Prevent multiple submit..." Watch "Prevent multiple submit..." New topic

Prevent multiple submit...

Azuritul Wu

Joined: Apr 21, 2004
Posts: 8
Hope this is the right place for this question.

This problem is confusing me for a period of time. It is primarily about the double submit problem.

The scenario is like the following:
My web app has a page that list all the report(in html button) the user can click. After the button is clicked, another window will pop out. In the popped out window, the user can choose the report's date range. After that, the user clicks the submit button in the popped out window, then the request is processed and an excel report is generated.

I use struts and iBatis in this web app.
So the flow of report processing is:
choose date range -> to ActionForm -> forward to the HttpServlet and process and output the xls report.

And here is the problem.

The window that let the user choose date range is still on the screen after the date is choosed and submitted. By this time, if the user click the submit button(in date choosing window) many times, the request will also be sent multiple times. Thus the content of the report generated will simply be wrong.

So, what should I do to prevent the user from double(or even more) submit?
Or, how do I tell the server to just ignore the second request if the first request is still in processing.

I tried Strut's TokenProcessor. But it seems not suitable for my problem.
Yes, I can ask the server to forward to different page after receiving the second request, the report will still be processed, but will be discarded afterwards(because the app forwards the second request to another page).
And it would just throw a "connection reset by peer" exception.

Any suggestion or advice is welcomed and appreciated.
Thank you.

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
There is an entry in the javaranch struts faq that addresses this:

This is a rather pathetic faq that only contains one entry, and it happens to address this topic.

Consultant, Sima Solutions
I agree. Here's the link:
subject: Prevent multiple submit...
jQuery in Action, 3rd edition