This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi All, Iam involved in the process of developing a web-based product, I am using struts and I have a problem of "Double-Submit" i.e) double clicking the SUBMIT button. How can I solve the Double click-problem so that , There is no processing when the user double clicks the Submit-button.
Our web application has one limitation , and this limitation is growing day by day. This limitation is because of stateless nature of http protocol. Struts framework has managed this problem specified below.
So please read this article and make required changes into your code. We will make some schedule so that our web application will be bug free in future.
Not Checking for Duplicate Form Submissions
Aside effect of the stateless nature of the HTTP protocol is that the interface
presented in the browser can easily get out of sync with the state of the
model on the server. There is a common pitfall involving this lack of synchronization
that must be dealt with in nearly every application. This occurs
when a user submits values using a form on a given page and then, at some
later point, backtracks to the cached page, edits the now stale values, and
resubmits the form. This has the potential to corrupt the underlying data
store by creating duplicate records, overwriting current data with stale values,
and so on. In the best case, it creates a bad transaction that is rejected by
the data store.
This pitfall potentially affects nearly every JSP containing a form tag. In
most projects, the problems show up during system test. Fortunately for
developers, system testers are generally wise enough to include scenarios
in their test scripts that expose this type of bug. Developers, on the other
hand, rarely test for these conditions.
The code that follows represents a typical naive form implementation that
is trapped in this pitfall. If we don�t do anything special to prevent it, the
user can use the HTML generated by this JSP to submit the same form multiple
// if we got this far, everything worked okay, so generate
Listing 4.5 Checking the token in SaveInvoiceAction. (continues)
// a new token.
Listing 4.5 (continued)
The final step is to deploy and test the code to make sure it functions
properly. Once you have a working implementation, you can add token
generation and checking wherever else it is needed. Extra care should be
taken in testing the solution to ensure that forms cannot be resubmitted
under any odd combinations of circumstances.
Joined: Sep 15, 2005
Hi Amit, It was a brief explanation and thank you very much. I tried an example, and I added a saveToken(request) to the Action that navigates the form and In the action that handles the form when I checked as , if(!isTokenValid(request)) System.out.println("Not Valid Token"); else System.out.println("Valid Token");
I always get " Not Valid Token " , why??? I should get "Valid Token", Am I Correct...