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 Methods executing twice 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 "Methods executing twice" Watch "Methods executing twice" New topic

Methods executing twice

Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
I am facing a strange problem. In my struts based application, certain methods are being executed twice. In some of these methods I am doing database transactions and those transactions are also being done twice.
Has anyone faced this problem?
Please tell me what can be done to avoid this problem.
Franck Tranchant
Ranch Hand

Joined: Aug 07, 2003
Posts: 75

If your action methods , including database access etc.. are executed twice, you can be 99% sure that your actions are actually called twice.
Incorrect use of javascript could explain that kind of behaviour.

Don't you have some javascript coded in your JSP's on events like onclick/onsubmit/image+href.. ?
If so, double-check the 'return' value to avoid your Form being posted twice.

alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
follow up to franck's comment. the most common problem is using html:submit (or input type submit) along with a javascript submit, instead of html:button (or input type button).

-/a<br />certified slacker...yes, my last name is 'do' - <a href="" target="_blank" rel="nofollow"></a>
Consider Paul's rocket mass heater.
subject: Methods executing twice
Similar Threads
db access inside static methods
Focus Lost - Getting called twice.
Synchronized keyword will help to resolve ny defect?
java bean each line twice being executed twice
Multiple Transactions