日期:2014-05-17  浏览次数:21026 次

jsp连接JavaBean出现“WrongName”

截的图就是报告的错误。
我是照着一本书的例子来的,就是应用<jsp:setProperty>动作设置JavaBean属性,有一个UserBean.java、UserForm.jsp和SetPropertyDemo.jsp。

UserForm很简单,只填写用户名和密码,然后提交到SetPropertyDemo.jsp就出现上面提示的错误了。

我在d盘下建立了一个myweb目录,在servlet中注册为\test(这些都应该没问题,以前的实验都成功了)。myweb中建立了WEB-INF\classes\JavaBean,然后把编译好的JavaBean.class放到里面。

SetPropertyDemo.jsp中相应的代码为:

<%@ page import = "JavaBean.*"%>

<jsp:useBean id = "user" scope = "page" class = "JavaBean.UserBean"></jsp:useBean>

UserBean.java中也写了这么一句:package JavaBean;

UserForm.jsp和SetPropertyDemo.jsp都放在d\myweb\WEB-INF下了。
我也找了JDK文档去看NoClassDefFoundError的解释:
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
感觉是“找不到虚拟机要加载的类的定义”。可是还是不知道该怎么做?
------解决方案--------------------
你编译的是JavaBean.class,类名也是JavaBean?
JSP里用到的是JavaBean.UserBean
------解决方案--------------------
检查一下你的类名;