aspose file tools*
The moose likes Struts and the fly likes multiple form submission Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "multiple form submission" Watch "multiple form submission" New topic
Author

multiple form submission

jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
hi guys

I was wondering if anyone has read this article. It talks about 'avoiding multiple form submissions in
struts'.

http://www.javaworld.com/javaworld/javatips/jw-javatip136.html?page=1


I was wondering why do we need that in the first place. If i make sure that
the form is submitted only once, then i dont need to make use of such a functionality, am i correct?

any inputs appreciated

thanks
J
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
You answer your own question in your post. If you "make sure that a form is submitted only once", you shouldn't have to worry about "avioding multiple form submissions" since you've made sure it is only submitted once.

If you aren't using a token, how are you making sure a form is submitted only once? If you are disabling the submit button using javascript, keep in mind that not all users may have javascript enabled. If you are checking for a duplicate entry somewhere in your business layer, that might be okay.

I prefer the method in the article, and then use javascript and some business logic to prevent duplicates.
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
>>>If you aren't using a token, how are you making sure a form is submitted only once?

well, in my action class i have something like below
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
try {

System.out.println("inside action class");
}
catch
{
}

}

when button is clicked in jsp , it comes to the above execute method and "inside action class" is printed ONCE in the console.
so is that not sufficient enough for me to be sure that the form is submitted only once.




thanks,
J
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
Usually a multiple form submission happens when either the user clicks submit twice before the resulting page comes up, or if the user submits the form once, navigates to another page and clicks "back" on their browser, or after the submittal they hit reload. The browser then asks the user if they want to repost the data. If they select yes, the form will be submitted again.

It doesn't look like you are doing anything to prevent this scenario.

You might not need to prevent multiple submissions, but "post"s (as opposed to "get"s) usually push data to a database, and if you want to prevent duplicates you should implement custom business logic and/or the token concept.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
As Dom pointed out...the problem is that when the user is on the "Add Employee" screen, they enter "Jay Roy" in the name field and then click the submit button 10 times in a row...will you now have 10 entries in the database for "Jay Roy"? The more usual case is that the user clicks the submit button, waits a few seconds, and then clicks the submit button again.

I have researched various strategies and ended up going with a client side JavaScript approach. My pages require JavaScript so that is not an issue. A full sever-side solution like that in the linked article is a bit complex. Plus I would have to implement my own version of the Struts token processing method to handle form submission from a popup window (a topic that I have asked about in the past).

- Brent
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
yeah, i agree with you that the serverside solution is a bit complex.can you please
share the javascript approach or point me to a site which does that.

thanks
J
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
actually , i have the solution

thanks guys,
appreciate your responces
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
For the record...the solution that I have been using is to add this code to a common javascript file that gets included in my jsp.


I then make a call to the method in my html:form tag.


- Brent
jay roy
Ranch Hand

Joined: Nov 16, 2006
Posts: 145
thanks lot Brent
 
 
subject: multiple form submission