File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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>
I agree. Here's the link:
subject: Methods executing twice
It's not a secret anymore!