Here is the action class:
public class MainActionHandler extends DispatchAction {
public ActionForward prepareEditComment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("saveToken");
saveToken(request);
return mapping.findForward("prepareEditComment.success");
}
public ActionForward editComment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("isTokenValid?");
if (isTokenValid(request,false)) {
System.out.println("resetToken");
resetToken(request);
}
return mapping.findForward("editComment.success");
}
public ActionForward doSomething(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("doSomething");
}
public
String getMethodName(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response,
String parameter) throws Exception {
return parameter;
}
}
Here is the struts config file:
<action path="/prepareEditComment"
type="MainActionHandler"
validate="false"
parameter="prepareEditComment"
scope="request">
<forward name="prepareEditComment.success" path="page1.jsp"/>
</action>
<action path="/editComment"
type="MainActionHandler"
name="editCommentForm"
parameter="editComment"
validate="false"
scope="request">
<forward name="editComment.success" path="page2.jsp"/>
</action>
<action path="/doSomething"
type="MainActionHandler"
parameter="doSomething"
validate="false"
scope="request">
<forward name="saveFolderPDF.success" path="/pages/main.jsp"/>
</action>
"prepareEditComment" prepares the form action "editComment". "editComment" is executed via POST request. I click on a link and Action "prepareEditComment" is executed via GET three times. I click on my submit button then "editComment" is executed, "isTokenValid" returns false. Then "editComment" is executed again, "isTokenValid" is true and "resetToken" is called.
"doSomething" is a simple action executed via GET request and runs three times.
If you use only POST requests you can prevent double submit with the token methods, but it is more a workaround than a solution. Why does struts execute the GET actions three times?