Andreas Daab

Greenhorn
+ Follow
since Dec 10, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Andreas Daab

Problem found, it was my fault and no error in struts. I use the NTLM protocol to authenticate the users and so every page is loaded three times.
Thank you for help!
19 years ago
The method "getMethodName" returns the name of the parameter "name" in the struts config file. It is easier to handle than a "DispatchAction" and the parameter "method" that has not to hand over in every action with hidden fields oder GET-parameters.
I disabled the method "getMethodName" in my action class, changed "name=firstAction" to "name=method" in the struts config file and added the parameter method in the redirect in "index.jsp" to
<logic:redirect page="/firstAction.do?method=firstAction"/>
The test output in "firstAction" is printed out two times, so this seems not to be the problem with the double or triple execution. I'll try out your idea with the "DispatchAction" and post the results.
19 years ago
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?
19 years ago
A simple "System.out.println("Hello world");" in your execute method of your action class and checking of "tomcat/logs/stdout.log" should do it. I noticed the problem when some SQL statements were executed more than once and I got double entries.
All POST request are executed twice and all GET request are executed three times.
Struts 1.2.4
Tomcat 5.0.28
19 years ago
In my application every action started with GET request (hmtl link) is executed three times !
How to fix this? Using saveToken(request) doesn't help and in my opinion it is a workaround and not a fix for this bug. See Prevent double submit for details.
Why struts calls the action three times?
19 years ago
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.
19 years ago
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?
19 years ago