求助:Cannot find ActionMappings or ActionFormBeans collection
最近在看Validate,刚刚动手做了个,但运行时总显示Cannot find ActionMappings or ActionFormBeans collection.我看了半天也没看出什么问题来,我用的是jBuilder2005做的,以下是全部代码:
actionForm:
package validate;
import org.apache.struts.validator.ValidatorForm;
public class CheckForm extends ValidatorForm {
private String age;
private String email;
private String passWord;
private String userName;
public String getAge() {
return age;}
public void setAge(String age) {
this.age = age;}
public void setUserName(String userName) {
this.userName = userName;}
public void setPassWord(String passWord) {
this.passWord = passWord;}
public void setEmail(String email) {
this.email = email;}
public String getEmail() {
return email;}
public String getPassWord() {
return passWord;}
public String getUserName() {
return userName;}
}
action:
package validate;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
public class SaveAction extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,HttpServletRequest servletRequest,
HttpServletResponse servletResponse) {
CheckForm checkForm = (CheckForm) actionForm;
return actionMapping.findForward( "success ");
}
}
jsp:
<%@ page contentType= "text/html; charset=GBK " %>
<%@ taglib uri= "/WEB-INF/struts-bean.tld " prefix= "bean " %>
<%@ taglib uri= "/WEB-INF/struts-html.tld " prefix= "html " %>
<html>
<head>
<title> JSP for CheckForm form </title>
</head>
<body>
<html:form action= "SavaAction.do ">
<bean:message key= "userName "/> : <html:text property= "userName "/> <html:errors property= "userName "/> <br/>
<bean:message key= "passWord "/> : <html:password property= "passWord "/> <html:errors property= "passWord "/> <br/>
<bean:message key= "age "/> : <html:text property= "age "/> <html:errors property= "age "/> <br/>
<bean:message key= "email "/> : <html:text property= "email "/> <html:errors property= "email "/> <br/>
<html:submit/> <html:cancel/>
</html:form>
</body>
</html>
validation.xml:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN " "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd ">
<form-validation>
<formset>
<form name= "CheckForm ">
<field property= "userName " depends= "required ">
<arg0 key= "userName "/>
</field>
<field property= "passWord " depends= "required,maxlength,minlength ">
<arg0 key= "passWord "/>
<var>
<var-name> maxlength </var-name>
<var-value> 12 </var-value>
</var>
<var>
<var-name> minlength </var-name>
<var-value> 6 </var-value>
</var>
</field>
<field property= "age " depends= "range ">
<arg0 key= "age "/>
<arg1 key= "18 " resource= "false "/>
<arg2 key= "30 " resource= "false "/>
<var>
<var-name> max </var-name>
<var-value> 30 </var-value>
</var>
<var>
<var-name> min </var-name>
<var-value> 18 </var-value>
</var>
</field>
<field property= "email " depends= "email ">
<arg0 key= "email "/>
</field>
</form>
</formset>
</form-validation>
web.xml:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<web-app xmlns= "http://java.sun.com/xml/ns/j2ee " xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd " version= "2.4 ">
<display-name> validate </display-name>
<jsp-config>
<taglib>
<taglib-uri> /WEB-INF/struts-bean.tld </taglib-uri>
<taglib-location> /WEB-INF/struts-bean.tld </taglib-location>
</taglib>
<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-template.tld </taglib-uri>
<taglib-location> /WEB-INF/struts-template.tld </taglib-location>
</taglib>
<taglib>
<taglib-uri> /WEB-INF/struts-tiles.tld </taglib-uri>
<taglib-location> /WEB-INF/struts-tiles.tld </taglib-location>
</taglib>
<taglib>
<taglib-uri> /WEB-INF/struts-nested.tld </taglib-uri>
<taglib-location> /WEB-INF/struts-nested.tld </taglib-location>
</taglib>
</jsp-config>
<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> application </param-name>
<param-value> ApplicationResources </param-value>
</init-param>
<load-on-startup> 2 </load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name> action </servlet-name>
<url-pattern> *.do </url-pattern>
</servlet-mapping>
</web-app>
struts-config.xml:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<!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= "checkForm " type= "validate.CheckForm " />
</form-beans>
<action-mappings>
<action input= "/user.jsp " name= "checkForm " path= "/saveAction " scope= "request " type= "validate.SaveAction " validate= "true ">
<forward name= "success " path= "/user.jsp " />
</action>
</action-mappings>
<plug-in className= "org.apache.struts.validator.ValidatorPlugIn ">
<set-property property= "pathnames " value= "/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml " />
</plug-in>
</struts-config>
感谢各位高手,请帮帮忙忙
[解决办法]
你的JSP页面的ACTION写错了,应该是/saveAction.do
你要注意的是JSP提交的ACTION要对应这个ACTION在struts-config.xml中这个ACTION的PATH属性完全一致.
如果你改了还不能的话,我介意你把struts-config.xml中ACTION中的INPUT属性去掉!