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方式一样
在Spring框架中,当出现"class path resource [springmvc cannot be opened because it does not exist"错误时,通常是因为Spring无法找到指定的资源文件。资源文件可以是配置文件、静态资源等。在这种情况下,需要检查以下几个方面: 1. 确保资源文件的路径和名称正确。检查是否在指定的位置存在名为"springmvc"的文件,并且路径是正确的。 2. 确保资源文件在类路径(classpath)中。类路径是指Java程序在运行时查找资源文件的路径。可以通过将资源文件放置在src/main/resources目录下,或者配置正确的类路径来解决该问题。 3. 确保项目的构建工具(例如Maven或Gradle)正确配置了资源文件的复制。构建工具负责将资源文件复制到编译后的目录中,以便在运行时可以找到。 综上所述,当出现"class path resource [springmvc cannot be opened because it does not exist"错误时,需要检查资源文件的路径、类路径和构建工具的配置。确保资源文件存在于正确的位置,并能够在运行时被找到。这样就可以解决该错误。<span class="em">1</span> #### 引用[.reference_title] - *1* [SSM相关面试题(包括Spring,SpringMVC,Mybaits在内的50道面试题)](https://download.csdn.net/download/Keep__Me/88214799)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值