问题错误提示:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.IllegalArgumentException: Resources cannot be null.
org.apache.commons.validator.Validator.<init>(Validator.java:188)
org.apache.struts.validator.Resources.initValidator(Resources.java:475)
org.apache.struts.validator.DynaValidatorForm.validate(DynaValidatorForm.java:104)
org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:950)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:207)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.0.28
有很多朋友在问同一个问题,其实问题很小的,请看下面错误例子:
1、JSP不用改变,例如,建立register.jsp,源代码如下:(不得了啦,这里上传HTML源代码,被解释成一个HTML页面效果了)
<form-property name="userName" type="java.lang.String" />
<form-property name="userPassword1" type="java.lang.String" />
<form-property name="userPassword2" type="java.lang.String" />
<form-property name="userEmail" type="java.lang.String" />
</form-bean>
4、添加Action子类RegisterAction,其代码如下:
package com.drc.action;
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 org.apache.struts.action.DynaActionForm;
public class RegisterAction extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm form,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
DynaActionForm form = (DynaActionForm) form;
System.out.println("userName = " + form.get("userName"));
System.out.println("userPassword1 = " + form.get("userPassword1"));
return actionMapping.findForward("registerSuccess");
}
}
5、在struts-config.xml中添加如下Action映射说明:
<action input="/register.jsp"
name="registerActionForm"
path="/registerAction"
scope="request"
type="com.drc.action.RegisterAction"
validate="true">//很多问题都出在这儿,这儿应该是validate="false",好多朋友把validate="false"写成了validate="true",但因为程序中没有配置validate,相关说明请参看 http://book.csdn.net/bookfiles/604/10060419564.shtml
<forward name="registerSuccess"
path="/userRegisterSuccess.jsp"
redirect="false" />
</action>
6、如果想在validator中执行验证,与一般ActionForm方式一样