Discussions

General J2EE: Execute() method is called twice in a struts based application?

  1. Please let me know the solution how to avoid this strange problem
    -Pratap
  2. How do you know its being executed twice? What are the forwards from the action?
  3. I have put some log statements and I came to know it is called twice..forward is usually the JSP page..
  4. I noticed similar behavior with Struts a while back. What I believe is happening is that the Action's execute method is only being used once but that Log4J actually logs messages from Actions twice. For example, if you were to have the method make an insert to a DB table, you would only find one entry. If you're logging that insert though, it would appear as though it were occuring twice.
  5. Hi,
    I have seen the similar kind of problem. Please check the code in JSP page. Sometimes, you may use button type "submit" for form and use javascript to submit the form. In this scenario, the browser sends the request twice.

    Hope, it helps!!!!

    Anil S.
  6. I think Anil is right. But sometimes, I am facing very starnge problems like even the codes present inside the execute method are executed in a multithreaded way. Well that is fine but sometimes it affects dependencies among code executions. This is eveident from the Log file(I am using log4j mechanism to debug).

    May be, I am not sure, log4j mechanism logs incorrectly as suggested by another fellow.

    Let me test again and will update you guys..
  7. I hv encountered the same problem of you. Sometimes it seems that the Execute() method was executed twice...since i hv inserted a record to DB everytime the method is executed...

    so, did you find any solution or discover something?
  8. Hey Anil, thaks so much ... this was a very good suggestion .. helped me !

    I registered just to thank you :)

  9. thanks[ Go to top ]

    Thanks a lot.. it was a good Catch.. I am using html:button instead of html:submit and on click I have a javascript function called which actually does the submit..

    In this scenario if you use html:submit , Action class is fired 2 times

  10. Hibernate[ Go to top ]

    Hey Anil Thanks a lot . i have solve my proble with help of your suggetion . 

  11. I also am experiencing this[ Go to top ]

    I have been experiencing a very similar problem, but it only seems to execute twice every once in a while (not every time). Were you able to discover the root of the problem?
  12. I am using struts with log4j and I am experiencing the same problem. Has anyone reached the conclusion yet as to whether it is just the log4j logging the message twice or indeed execute() method is being called twice. I see the message logged twice ALMOST all the time (but NOT everytime) meaning for most of the Action classes, message is logged twice beside just one Action class so I am bit confused as to what is actually going on here. Any help would be greatly appreciated.
  13. make sure you don't have any empty image tags in your page. I had the same issue and i found that caused the problem.
  14. You are the man![ Go to top ]

    Hey Darren I know this thread is long dead... Nonetheless - well done! You just saved me a huge headache. I googled this problem and found a dozen answers by people who had no real idea what they were talking about. Then I read your post and - poof! Thanks, brother. PS: I'm hand-coding the JSP pages - no Struts involved...
  15. I have the same problem where the action class gets called twice .This happens more often the production than on our test environment.In production it doesnt occur always but what i noticed is that it occurs when the n/w is slow(my observations) I have read all the threads and have checked for the below 1.There are no double submits from the jsp's level (i.e we do not have both a html submit and a java script form submit) .Rather we have an image which when clicked calls a java script which checks for certain parametes and alerts the user via a modal box .Once the user clicks Ok the javascript submits the form 2.I have checked and we do not have empty img tag 3.Its looks like the Action class gets invoked twice by two seperate threads,is this a know error with struts Any help on this is much appreciated