首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

问个简单的使用JaveBean的有关问题

2013-09-11 
问个简单的使用JaveBean的问题.最近初学JSP,按着书上敲了几个JaveBean,但总是出现同一个错误,执行不了,想

问个简单的使用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; 


换成:
private int count = 0; 
public Counter() 

}
[解决办法]
WEB-INF目录名要大写
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行