• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Actions executed three times

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How did you find that it runs 3 times?
 
Andreas Daab
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ilja Smoli
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe if you provide a code of your action class...
 
Andreas Daab
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ilja Smoli
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have run your action class on my Tomcat 4.0, 4.1 and 5.0 (struts 1.2.4), everything ok, it executes ONCE.
Second thing that look strange for me is your action mappings:
your get link will look smth like :
prepareEditComment.do?prepareEditComment=prepareEditComment

I'd prefer like this:

And 3rd thing (as I found): "path" attribut of forward must start with "/" (slash)
Thats all I can say..
 
Andreas Daab
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Andreas Daab
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic