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 class execute method not getting called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Action class execute method not getting called" Watch "Action class execute method not getting called" New topic
Author

Action class execute method not getting called

Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
Hello all,
I am trying to run a simple struts application.
When I am submitting the JSP,the action form validate method is called successfully but my action class execute method is never called.

The URL is displayed blank with the /item.do

Please help

Thanks,
Shriya
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Are you completely sure the execute method is not getting called? Have you put a System.out.println statement somewhere in the method to see if it gets printed?

In my experience, when you get a blank page with the correct URL showing, that means the action didn't return a forward. This could be a simple as misspelling the forward name. For example: mapping.findForward("sucess") instead of mapping.findForward("success");


Merrill
Consultant, Sima Solutions
Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
Thanks for your response.

I have put System.out in the very first line of action class.
Code snippet:
JSP:
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html>
<head>
<title>Web JSP</title>
</head>
<body>
<html:errors/>
<html:form action="/submit.do">
Lastname <html:text property="lastname"/>
Address <html:textarea property="address"/>

Married <html:checkbox property="married"/>

<html:submit/>
</html:form>
</body>
</html>

Struts Config :
<action path="/submit"
type="web.WebAction"
name="webForm"
input="/web.jsp"
scope="request"
validate="true">
<forward name="success" path="/index.jsp"/>
<forward name="failure" path="/error.jsp"/>
</action>

Action class :
public ActionForward execute(ActionMapping mapping,HttpServletRequest request, ActionForm form,HttpServletResponse response){

System.out.println("enter action");
WebForm webform=(WebForm)form;
String lastname=webform.getLastname();
request.setAttribute("lastname",lastname.toUpperCase());
return(mapping.findForward("success"));
}
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Your execute method has the wrong signature. The required parameters are all there, but they are in the wrong order. Your execute method must have exactly the following signature:
Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
thank you very much .I got my issue solved.Thanks once again
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
i am also facing the same problem, even though my execute method has correct signature. please find below the code for LoginAction class:



s.o.p. statement written in the constructor is getting called but s.o.p. written in the execute method is not getting called. please help me out.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You already have one thread open for this; please use only one thread per question.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Action class execute method not getting called
 
Similar Threads
Action class constructor - is it called every time ,,,,,,
execute method of ActionSupport Class
problem in excluding the parameter in validation interceptor
user defined method in struts 2 action class
struts 2: how to call action from href link