aspose file tools*
The moose likes Struts and the fly likes method in dispatch action is executing more than once Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "method in dispatch action is executing more than once" Watch "method in dispatch action is executing more than once" New topic
Author

method in dispatch action is executing more than once

Mohit Kumar Tayal
Greenhorn

Joined: Aug 27, 2008
Posts: 29
Hello,

i am working with struts framework 1.2. i have created a class by extending the class DispatchAction and defined some method therein. when i request from the browser some method are executing more than once.

actually i am printing hello in the method to debug the code and hello is printing 1-3 times randomely on requests for the method.

please give me some idea why this behaviour is coming. please tell me one more thing that when the object of this class will be created by the framework and where it is stored.

Thank you.
Prakash Mani - Attur
Ranch Hand

Joined: Oct 08, 2009
Posts: 100
the object of the action class will be created after the form bean validations are successful. how you are calling this method. provide the jsp file and struts config file..
Mohit Kumar Tayal
Greenhorn

Joined: Aug 27, 2008
Posts: 29
public ActionForward home(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {


process(mapping, form, request, response);

System.out.println(System.currentTimeMillis());

return mapping.findForward("home");
}

This is the code in IndexAction Class that is extending the class DispatchAction and in struts-config.xml i am mapping the home to index.jsp page as follows:

<forward name="home" path="/index.jsp" />

Now the process method actually do some database level tasks and store the information in a map that i am showing in index.jsp. this process method do processing which is based on some request parameter and it is showing unexpected behaviour like on different values for parameters showing different result.

for some values it is printing only one time for others two time and for some three time also.

one point also i want to tell is i have a hyperlink anchor tag in the jsp page that is referring to the same page with default values of parameter and if i am opening the page by clicking the link it is printing two times but when i am refreshing the browser window it is printing three times.

is there any difference between the requests send by clicking the hyperlink and refreshing the browser window with same url.

i am very surprised when i saw this type of behaviour. please help me on this.

Thank you.
Prakash Mani - Attur
Ranch Hand

Joined: Oct 08, 2009
Posts: 100
hi mohit
can you please post all your files( index.jsp, IndexAction.java and struts-config.xml )
thank you
Mohit Kumar Tayal
Greenhorn

Joined: Aug 27, 2008
Posts: 29
hi prakash,
i have found the problem actually the problem is not in the struts code because it is doing well with other browsers like ie and mozila. the problem is with google chrome actually it is creating problem by sending more than one request to the server.

now i am trying to findout why google chrome is behaving in different way.
thanks for your help.
Prakash Mani - Attur
Ranch Hand

Joined: Oct 08, 2009
Posts: 100
happy to see your problem solved.. let me know the reason why chrome behaving differently after you have found it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: method in dispatch action is executing more than once