Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Action class execute method not getting called

 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much .I got my issue solved.Thanks once again
 
vikas sharmaa
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You already have one thread open for this; please use only one thread per question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic