问题错误提示:
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页面效果了)
view plaincopy to clipboardprint?
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
<form name="form1" accept-charset="UNKNOWN" action="registerAction.do" method="post" >
<table cellSpacing="0" cellPadding="3" width="301" border="0">
<tr>
<td noWrap="true" width="61">用户名:</td>
<td width="196">
<input type="text" name="userName" />
</td>
</tr>
<tr>
<td height="30">
<td noWrap="true" height="30">密 码:</td>
<td>
<input type="password" name="userPassword1" />
</td>
</tr>
<tr>
<td height="30">
<div align="center"></div>
</td>
<td noWrap="true" height="30">确 认:</td>
<td>
<input type="password" name="userPassword2" />
</td>
</tr>
<tr>
<td height="30">
</tr>
<input type="submit" value=" 确 定 " />
</td>
</tr>
</tbody>
</table>
</form>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/myok6/archive/2009/03/20/4006391.aspx
<form name="form1" accept-charset="UNKNOWN" action="registerAction.do" method="post" >
<table cellSpacing="0" cellPadding="3" width="301" border="0">
<tr>
<td noWrap="true" width="61">用户名:</td>
<td width="196">
<input type="text" name="userName" />
</td>
</tr>
<tr>
<td height="30">
<td noWrap="true" height="30">密 码:</td>
<td>
<input type="password" name="userPassword1" />
</td>
</tr>
<tr>
<td height="30">
<div align="center"></div>
</td>
<td noWrap="true" height="30">确 认:</td>
<td>
<input type="password" name="userPassword2" />
</td>
</tr>
<tr>
<td height="30">
</tr>
<input type="submit" value=" 确 定 " />
</td>
</tr>
</tbody>
</table>
</form>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/myok6/archive/2009/03/20/4006391.aspx
2、不用写ActionForm子类文件
3、需要在struts-config.xml文件中加入如下actionForm映射:
<form-bean name="registerActionForm(虚构的)" type="org.apache.struts.action.DynaActionForm">
<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方式一样