日期:2014-05-18  浏览次数:20781 次

问个简单的使用JaveBean的问题.
最近初学JSP,按着书上敲了几个JaveBean,但总是出现同一个错误,执行不了,想请教下各位.
JavaBean代码:
package ch7;
public class Counter {
private int count;
public Counter()
{
count = 0;
}
public int getCount()
{
count++;
return count;
}
public void setCount(int value)
{
count = value; 
}
}

jsp页面代码:
<%@ page contentType="text/html; charset=GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JavaBean应用示例</title>
</head>
<body>
<jsp:useBean id="bean1" scope="application" class="ch7.Counter" />
<%
out.println("当前的计数为:" + bean1.getCount() +"<br>");
%>
</body>
</html>

我用的JDK版本是1.5.0_05
Tomcat版本是5.5.23
工具是Eclipse v3.2
jsp文件路径是:
E:\Courses\jsp\mytomcat\mybean.jsp
JavaBean相关的路径是:
E:\Courses\jsp\mytomcat\web-inf\src\ch7\Counter.java
E:\Courses\jsp\mytomcat\web-inf\classes\ch7\Counter.class

出错提示如下:
type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: /mytomcat/mybean.jsp(8,4) The value for the useBean class attribute ch7.Counter is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1175)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1117)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2164)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2214)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2220)
org.apache.jasper.compiler.Node$Root.accept(Node.java:457)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2164)
org.apache.jasper.compiler.Generator.generate(Generator.java:3322)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:296)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:299)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.

麻烦各位知道该怎么修改告诉下,先谢谢了!

------解决方案--------------------
试了一下LZ代码 
没有问题啊...
能运行啊...
------解决方案--------------------
嗯 ,能运行呀 ;

不过 javabean 规范 不是LZ写的 那样吧~~~
------解决方案--------------------
是不是环境问题
------解决方案--------------------
你试一下把这里:
private int count; 
public Counter() 

count = 0; 


换成:
priv