| Author |
Cannot find ActionMappings or ActionFormBeans
|
Betsy Camel
Ranch Hand
Joined: Oct 02, 2003
Posts: 119
|
|
i am getting the above error when i tried my first struts application. here is the code. Can anyone help me ! //login.jsp <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body><html:form action = "/login"> Name<html:text property = "name"/> Password<html:text property = "password"/> <html:submit property = "submit"/> </html:form> </body> </html> //gettersActionForm package strut; import javax.servlet.http.HttpServletRequest; import org.apache.struts.*; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; public class gettersActionForm extends ActionForm{ /** * @param args */ String name; String password; public void setName(String name){ System.out.println("setting name" +name); this.name = name; } public void setPassword(String password){ this.password = password; } public String getName(){ return name; } public String getPassword(){ return password; } } //ControlAction package strut; import javax.servlet.ServletException; import javax.servlet.http.*; import javax.sql.*; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import java.io.IOException; import java.sql.*; public class ControlAction extends Action{ /** * @param args */ public ActionForward perform(ActionMapping map, ActionForm form, HttpServletResponse res, HttpServletRequest req) throws IOException, ServletException{ String target = ""; System.out.println("hello"); String username = ((gettersActionForm)form).getName(); String pwd = ((gettersActionForm)form).getPassword(); System.out.println(username); System.out.println(pwd); if(username.equals("laxmi")&&(pwd.equals("laxmi"))){ target = "success"; } else { target = "failure"; } System.out.println("target"+target); return (map.findForward(target)); } } //struts-config.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> <struts-config> <form-beans> <form-bean name="gettersActionForm" type="strut.gettersActionForm" /> </form-beans> <action-mappings> <action path="/login" name="gettersActionForm" type="strut.ControlAction" scope="request" input="/login.jsp"> <forward name="success" path="/hello.jsp"/> <forward name="failure" path="/bad.jsp"/> </action> </action-mappings> </struts-config> //web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <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> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <taglib> <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib> </web-app> the exception - javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:741) org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:443) org.apache.jsp.login_jsp._jspx_meth_html_form_0(org.apache.jsp.login_jsp:100) org.apache.jsp.login_jsp._jspService(org.apache.jsp.login_jsp:74) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
|
 |
Betsy Camel
Ranch Hand
Joined: Oct 02, 2003
Posts: 119
|
|
|
I am unable to find the reason for the above error. Please help
|
 |
Betsy Camel
Ranch Hand
Joined: Oct 02, 2003
Posts: 119
|
|
|
I am unable to find the reason for the above error. Please help
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
This message is an indication that the Struts ActionServlet didn't initialize properly. Look at the entries in your Application Server log that occur when you first start the server or start the Struts application. I suspect you will find some sort of error there that is the root cause of the problem. Once you find the error, post it here, and we'll help you fix it. The most common error is a parsing error, meaning that Struts can't parse the XML in your struts-config.xml file.
|
Merrill
Consultant, Sima Solutions
|
 |
Betsy Camel
Ranch Hand
Joined: Oct 02, 2003
Posts: 119
|
|
The following is the log found in the server INFO: validateJarFile(C:\Program Files\Apache Software Foundation\T apps\Struts\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Serv section 9.7.2. Offending class: javax/servlet/Servlet.class log4j:WARN No appenders could be found for logger (org.apache.catal anagerBase). log4j:WARN Please initialize the log4j system properly. Jan 19, 2006 9:38:53 AM org.apache.catalina.loader.WebappClassLoade File INFO: validateJarFile(C:\Program Files\Apache Software Foundation\T apps\test\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servle ection 9.7.2. Offending class: javax/servlet/Servlet.class Jan 19, 2006 9:38:54 AM org.apache.coyote.http11.Http11Protocol sta INFO: Starting Coyote HTTP/1.1 on http-8000 Jan 19, 2006 9:38:54 AM org.apache.jk.common.ChannelSocket init INFO: JK2: ajp13 listening on /0.0.0.0:8009 Jan 19, 2006 9:38:54 AM org.apache.jk.server.JkMain start INFO: Jk running ID=0 time=0/359 config=null Jan 19, 2006 9:38:54 AM org.apache.catalina.startup.Catalina start INFO: Server startup in 13266 ms what does servlet-jar not loaded mean ?
|
 |
shahin Khan
Greenhorn
Joined: Mar 04, 2005
Posts: 17
|
|
Add servlet api.jar file in ur web-inf/lib folder and then try to execute Hope it will work out. Cheers Shahin
|
 |
Reid M. Pinchback
Ranch Hand
Joined: Jan 25, 2002
Posts: 775
|
|
Originally posted by Betsy Camel: The following is the log found in the server INFO: validateJarFile(C:\Program Files\Apache Software Foundation\T apps\Struts\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Serv section 9.7.2. Offending class: javax/servlet/Servlet.class what does servlet-jar not loaded mean ?
This isn't causing your struts problem. It is a spec violation for you to put one of the J2EE API jars into an application. You are just seeing an info-level logging message warning you that the container saw the jar, but ignored it instead of loadings its classes. It didn't need the classes, and loading could have conflicted with the classes already loaded by the container from its own internal libraries.
|
Reid - SCJP2 (April 2002)
|
 |
Betsy Camel
Ranch Hand
Joined: Oct 02, 2003
Posts: 119
|
|
I had not added the <load-on-startup> tag in the web.xml . So solved the above problem. But got into another The application is getting redirected to the login.do file which is blank . Can anyone resolve this . thanks Betsy
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
One possible cause of this would be the action class not returning a valid ActionForward. Make sure there's a statement similar to: return mapping.findForward("xyz"); in your action class. Then make sure that "xyz" or whatever is defined as either a global or local forward in your struts-config.xml file.
|
 |
Betsy Camel
Ranch Hand
Joined: Oct 02, 2003
Posts: 119
|
|
|
I have placed the code above . Though i have specified all the tags, the application gets directed to the .do file, Please let me know how to resolve this.
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
Even though the URI on the page says "login.do", it should actually be displaying either "hello.jsp" or "bad.jsp" depending on whether the login succeeded or failed. One thing you might do is put the following statement after System.out.println("target"+target); in your Action: System.out.println("ActionForward: "+ map.findForward(target))); If you get null, it means the ActionForward wasn't found. If you get anything other than null, the problem is something else. Another possibility to consider is that hello.jsp or bad.jsp may have malformed html. Use your browser's "view source" option on the blank page to see if there are html tags there that are not being displayed. [ January 20, 2006: Message edited by: Merrill Higginson ]
|
 |
Deb
Greenhorn
Joined: Jan 19, 2006
Posts: 2
|
|
I have the same error. The browser is going to the Lookup.do but the page is blank. Let me know your resolution... )
|
-Deb
|
 |
Betsy Camel
Ranch Hand
Joined: Oct 02, 2003
Posts: 119
|
|
hi thats right. I tried putting a System.out.println in the Action class but it didnt get displayed. Does this mean that control doesnt flow into the action class itself. How do i correct this issue ?
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
|
Change the name of your method in your action class from perform() to execute(). You may be looking at an old copy of the tutorial. In previous versions of Struts, perform() was the name of the method to be overridden in the Action class, but in later versions it's execute()
|
 |
Betsy Camel
Ranch Hand
Joined: Oct 02, 2003
Posts: 119
|
|
|
Yep! i have changed perform() to execute(), nut couldnt find any change in the application.
|
 |
 |
|
|
subject: Cannot find ActionMappings or ActionFormBeans
|
|
|