百思不得其解,无法使用javabean,高分求教
我搜索了板块上关于无法使用javabean的帖子,发现还是无法解决我的问题,描述如下:
虚拟目录myapp
jsp放在myapp/下,不调用bean时,可以正常访问,servlet也可以正常访问
写了一个bean如下
package beans;
public class hello
{
public hello()
{
System.out.println("Hello!");
}
}
编译以后,把hello.class放在myapp/WEB-INF/classes/beans/ 下
然后写了一个test.jsp放在myapp/ 下,其中有
<jsp:useBean id="s" scope="page" class="beans.hello"/>
<%
s.hello();
%>
运行test.jsp,错误如下:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 9 in the jsp file: /1.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\tools\Tomcat 5.0\work\Catalina\localhost\myapp\org\apache\jsp\_1_jsp.java:42: cannot access beans.hello
An error occurred at line: 9 in the jsp file: /1.jsp
Generated servlet error:
bad class file: D:\work\programme\JSP\WEB-INF\classes\beans\hello.class
class file contains wrong class: hello
Please remove or make sure it appears in the correct subdirectory of the classpath.
beans.hello s = null;
^
1 error