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

使用javabean超级简单问题
javabean代码:
public   class   Counter  
{
//public   long   count=0;
//public   String   Name;
public   String   GetPower(int   i)
{
if(i> 0)
{
return   "> 0 ";
}
else
{
return   " <0 ";
}
}
}


jsp代码:
<%@   page   contentType= "text/html;charset=GB2312 "   %>
<jsp:useBean   id= "counter "   class= "Counter "   scope= "application ">
</jsp:useBean>
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN ">
<html>
    <head>
        <title> My   JSP   'index.jsp '   starting   page </title>
        <meta   http-equiv= "pragma "   content= "no-cache ">
        <meta   http-equiv= "cache-control "   content= "no-cache ">
        <meta   http-equiv= "expires "   content= "0 ">
        <meta   http-equiv= "keywords "   content= "keyword1,keyword2,keyword3 ">
        <meta   http-equiv= "description "   content= "This   is   my   page ">
    </head>
   
    <body>
        This   is   my   JSP   page.   <br>
        <%=counter.GetPower(1)%>
    </body>
</html>

输出总出错:
type   Exception   report

message  

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

exception  

org.apache.jasper.JasperException:   /index.jsp(2,0)   The   value   for   the   useBean   class   attribute   Counter   is   invalid.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root   cause  

org.apache.jasper.JasperException:   /index.jsp(2,0)   The   value   for   the   useBean   class   attribute   Counter   is   invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
org.apache.jasper.compiler.Node$Us