This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
Similar Threads
saveToken & isTokenValid don't work
Browser Refresh
using saveToken() and isTokenValid() methods in struts
Duplicate submission problem
Actions executed three times