Ensure that your are having your struts-config like the one below. And also please check your class path
regards, Sunny
<?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_2.dtd">
<struts-config>
<form-beans>
<form-bean name="articleForm" type="articles.ArticleForm"/>
</form-beans>
<action-mappings> <action path="/Article" type="articles.ArticleAction" name="articleForm" scope="request" validate="true" input="/Template.jsp"> <forward name="success" path="/preview.jsp"/> <forward name="failure" path="/Template.jsp"/> </action> </action-mappings>
</struts-config>
uma.k wrote:
Hello, I am new to Struts, my first application is giving me this error. I am using Tomcat 4.0 and struts 1.2.4. Where did I go wrong? Please help me. javax.servlet.ServletException: Cannot find ActionMappings or ActionFormBeans collection
Here are my files
-----Template.jsp
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <html> <body> <html:form action="/Article">
<table border="0" width="100%"> <tr> <td width="18%"><font size="2" face="Verdana">Keywords</font></td> <td width="32%"><input type="text" name="keywords" size="60"> </td> </tr> </table> <html:submit>Submit</html:submit>
</html:form>
---- web.xml <?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<!-- Standard Action Servlet Configuration (with debugging) --> <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> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>2</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet>
<!-- Standard Action Servlet Mapping --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>
<!-- Struts Tag Library Descriptors --> <taglib> <taglib-uri>/WEB-INF/struts-bean</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib>
<taglib> <taglib-uri>/WEB-INF/struts-html</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib>
<taglib> <taglib-uri>/WEB-INF/struts-logic</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib>
<taglib> <taglib-uri>/WEB-INF/struts-nested</taglib-uri> <taglib-location>/WEB-INF/struts-nested.tld</taglib-location> </taglib>
<taglib> <taglib-uri>/WEB-INF/struts-tiles</taglib-uri> <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location> </taglib>
</web-app>
----struts-config.xml
<form-beans> <form-bean name="articleForm" type="articles.ArticleForm"/> </form-beans>
<action-mappings> <action path="/Article" type="articles.ArticleAction" name="articleForm" scope="request" validate="true" input="/Template.jsp"> <forward name="success" path="/preview.jsp"/> <forward name="failure" path="/Template.jsp"/> </action>
</action-mappings>
--ArticleForm.java
package articles;
import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionErrors;
public class ArticleForm extends ActionForm { private String keywords = null;
public String getKeywords(){ return keywords; }
public void setKeywords(String keywords){ this.keywords = keywords; }
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if( getKeywords() == null || getKeywords().length() < 1 ) { errors.add("keywords",new ActionMessage("error.keywords.required")); }
return errors;
} }
--ArticleAction.java
package articles;
import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; 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 articles.ArticleForm;
public class ArticleAction extends Action { private String keywords = null;
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String target = new String("success");
if(form != null) { // Use the ArticleForm to get the request parameters ArticleForm articleForm = (ArticleForm)form; keywords = articleForm.getTitle(); }
// if no title is supplied, set the target to failure if ( keywords == null ) { target = new String("failure"); } else { request.setAttribute("keywords", keywords); }
return (mapping.findForward(target)); }
}
Thank you, Uma
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]