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

jsp中javabean的问题
小弟初学jsp,在有关学习javabean的过程中有个问题希望大家帮忙解决。
Tomcat   5.0
虚拟站点设置为:在conf目录下server.xml中 </host> 前加了   <Context   path= "/jsp "   docBase= "F:\jsp "   reloadable= "true "   debug= "0 ">
  </Context>
-------javabean:------------
package   test;
public   class   Counter{
int   Count=1;
public   Counter(){
}
public   void   addCount(){
Count++;
}
public   int   getCount(){
return   Count;
}
}
---------jsp-------
<%@   page   contentType= "text/html;charset=gb2312 "%>  
<jsp:useBean   id= "counter "   scope= "session "   class= "test.Counter "   />
<br>
第一页
<br>
您一共访问了
<%
out.println(counter.getCount());
counter.addCount();
%> 个页面。
我将Counter.class放在F\jsp\WEB-INF\classes\test下,
但是运行时出问题:
org.apache.jasper.JasperException:   /sessionCounter.jsp(2,0)   The   value   for   the   useBean   class   attribute   test.Counter   is   invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1227)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3272)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

解决?

------解决方案--------------------
改成
<%@page import= "test.Counter " %>
<%
Counter counter=new Counter();
.
.
.
%>
------解决方案--------------------
少了 <%@page import= "test.Counte "%>
同意楼上