Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Action not being called in struts

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Which version of struts you are using?
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its working fine now..

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

Thankss a ton!!


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic