File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Action not being called in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Action not being called in struts" Watch "Action not being called in struts" New topic
Author

Action not being called in struts

Vijaya Parvathaneni
Greenhorn

Joined: Nov 29, 2012
Posts: 3
HI All,
I am trying to write a simple code in struts. The folowing are what I did
- Configured action in web.xml

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

- Configured Form and Action in struts-config.xml file
<struts-config>

<form-beans>
<form-bean name="helloWorldForm" type="com.uhg.HelloWorldForm"></form-bean>
</form-beans>
<action-mappings>
<action path="/helloWorld" type="com.uhg.HelloWorldAction" name="helloWorldForm">
<forward name="succes" path="/jsp/sucess.jsp"/>
<forward name="fail" path="/jsp/failure.jsp"/>
</action>
</action-mappings>

</struts-config>

- The below is my Action class

public class HelloWorldAction extends Action {

public ActionForward execute(ActionForm form, ActionMapping mapping,
HttpServletRequest req, HttpServletResponse res) {

System.out.println("-----------Entered Action--------");
return mapping.findForward("success");
}
}

When I am trying to run the application on my server, the action is not being called. Its showing the logs as below and Action is not being called.

[11/30/12 10:53:24:802 IST] 00000017 ComposableReq I org.apache.struts.chain.ComposableRequestProcessor init Initializing composable request processor for module prefix ''
[11/30/12 10:53:24:833 IST] 00000017 CreateAction I org.apache.struts.chain.commands.servlet.CreateAction createAction Initialize action of type: com.uhg.HelloWorldAction

Please help me in showing me where I went wrong. Any small help is highly appreciable.

Thanks in Advance.
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Hi,

Which version of struts you are using?


Thanks,
Shailesh
Vanessa Danin
Ranch Hand

Joined: Oct 04, 2004
Posts: 34
It looks like Vijaya is using Struts 1. Vijaya, two issues I noticed were:
1) The Struts Action class has an execute method defined with these parameters in this order: (ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res). However, your execute method has the ActionForm parameter declared first followed by the ActionMapping parameter.
2) You haven't shown your view using a path mapped to your Action class (i.e. does the jsp you are using to invoke this Action class have the form action value set to helloWorld.do?).
Vijaya Parvathaneni
Greenhorn

Joined: Nov 29, 2012
Posts: 3
Its working fine now..

The only change made was the sequence of the execute method parameters.

Thankss a ton!!


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Action not being called in struts