`
xidajiancun
  • 浏览: 492304 次
文章分类
社区版块
存档分类
最新评论

Resources cannot be null

 
阅读更多

问题错误提示:

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页面效果了)


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方式一样
分享到:
评论

相关推荐

    东软代码规范编写大全

    throw new IllegalArgumentException("Username cannot be null or blank."); } // 检查密码是否为空 if (StringUtils.isBlank(password)) { throw new IllegalArgumentException("Password cannot be null or...

    SCJP Sun® Certified Programmer for Java™ 6 Study Guide chapter 5

    - **NumberFormatException**: Thrown when a string cannot be parsed into a numeric format. By mastering these concepts, you will be well-equipped to handle various scenarios in Java programming, ...

    微软内部资料-SQL性能优化5

    Because the trees are balanced, finding any record requires about the same amount of resources, and retrieval speed is consistent because the index has the same depth throughout. Clustered and ...

    Delphi7.1 Update

    * A TLargeIntField cannot be used as a linking field in a master/detail relationship. Doing so results in the error &quot;Cannot access field &lt;fieldname&gt; as type variant.&quot; * TClientDataSet doesn...

    SSD7 选择题。Multiple-Choice

    For two tables to be union compatible, the tables should be the same with respect to which of the following? (a) keys (b) cardinality (c) name (d) degree Correct answer is (d) Your ...

    Java 编程 :常见问题汇总

    Objects.requireNonNull(obj, "obj cannot be null"); // 处理非空的obj } ``` 3. **数组越界:** 当访问数组元素时,应当确保索引值不会超出数组的有效范围。可以通过使用循环边界检查或使用`Arrays.asList()`...

    微软内部资料-SQL性能优化3

    Some of the resources have “sub-resources.” The followings are sub-resources displayed by the sp_lock output: Database Lock Sub-Resources: Full Database Lock (default) [BULK-OP-DB] – Bulk Operation...

    JavaExceptionsExtraclass

    throw new NullPointerException("File cannot be null"); } ``` 在编写异常处理代码时,应遵循一些最佳实践: - 尽量避免空指针异常,通过在使用对象前检查是否为null。 - 使用具体异常类,而不是笼统的`...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Friends Exceptions Run-Time Type Information (RTTI) Casting Streams Preincrement and Predecrement Use of const Integer Types 64-bit Portability Preprocessor Macros 0 and NULL sizeof Boost C++0x ...

    acpi控制笔记本风扇转速

    ResourceTemplate, but cannot be disassembled as such because the EndTag does not appear at the very end of the buffer. AcpiExec - Added the "-t" command line option to enable the serialized mode of ...

    Effective C#

    throw new ArgumentException("Age cannot be negative."); _age = value; } } ``` **Item 2: Prefer readonly to const** - **Purpose:** `readonly` variables are initialized once and can't be changed,...

    Struts常见错误汇总

    - 如果是由于 NullPointer 异常,检查是否有 null 值被引用。 #### 10. Resources not defined for Validator **问题描述:** 在使用 Struts 的 Validator 组件进行表单验证时,如果配置文件中未定义所需的资源,...

    struts常见异常及处理

    - 如果是 `NullPointerException`,则关注是否有为 null 的引用被使用,通常是配置文件未被正确加载。 以上总结了 Struts 框架开发过程中常见的异常及其处理方法。针对每种异常,都给出了详细的解释与解决步骤。...

    win 3.11 for workgroup tcpip支持

    containing the LMHOSTS file must be in the Null Sessions list on the Server by adding the share name to the following Windows NT Registry key: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services \...

    servlet2.4doc

    Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked. doFilter(ServletRequest, ...

    应用Dephi 开发佳能照相机API

    Calling this function releases all resources allocated by the libraries. This function delete all the reference or list objects that user has forgotten to delete. Parameters: In: None Out: ...

Global site tag (gtag.js) - Google Analytics