aspose file tools*
The moose likes Struts and the fly likes Prevent double form submit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Prevent double form submit" Watch "Prevent double form submit" New topic
Author

Prevent double form submit

Andreas Daab
Greenhorn

Joined: Dec 10, 2004
Posts: 7
I have an action prepareEditComment that opens a form and an action editComment that saves something in the database, prepareEditComment is executed via GET, editComment via POST.
With every single click prepareEditComment is executed three times and editComment twice!
saveToken(request) in prepareEditComment and isTokenValid(request) doesn't work for me, because isTokenValid always returns false.

I use struts 1.2.4 on Tomcat 5.0.28.

The following should work, but it doesn't:

public ActionForward prepareEditComment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("prepareEditComment");
saveToken(request);
return mapping.findForward("prepareEditComment.success");
}

public ActionForward editComment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("editComment");
if (isTokenValid(request)) {
doSomething();
} else {
resetToken(request);
}
}

Any ideas?
Andreas Daab
Greenhorn

Joined: Dec 10, 2004
Posts: 7
Not the second call off editComment is the problem, but the first. At the first call the form contains no values. Don't know which of the three prepareEditComment calls ist the correct one.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Prevent double form submit