bean应该放在包里,在你的程序里用上package关键字,然后再用调用.

解决方案 »

  1.   

    你是指把Demo.class放在一个jar包里,然后放在classes目录下吗?
      

  2.   

    我说的不是打包成jar,只是在你bean的最前面加上一名package yourPackageName,编译通过后再调用yourPackageName.Demo就行了.
      

  3.   

    这是原文件:
    package mypk;
    public class Demo
    {
    String name="";
    public void setName(String aName)
    {
    name=aName;
    }
    public String getName()
    {
    return name;
    }
    }
    编译完后,只给出了class,没有包喔...
      

  4.   

    你如果这样写的话:
    package mypk;
    public class Demo{
    ……
    }
    要将生成的类文件放到web-inf\classes\mydk下就可以了
      

  5.   

    对啊..我就是这样放的,但还是出错..
    我怀疑是我的Tomcat有问题,我装的是5.0版本
    这两天一直在搞这个,烦死~
    谢谢大侠指导喔.....
      

  6.   

    org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 10 in the jsp file: /ub.jspGenerated servlet error:
        [javac] Compiling 1 source fileC:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\ub_jsp.java:42: cannot resolve symbol
    symbol  : class Demo 
    location: package mypk
          mypk.Demo demo = null;
              ^An error occurred at line: 10 in the jsp file: /ub.jspGenerated servlet error:
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\ub_jsp.java:44: cannot resolve symbol
    symbol  : class Demo 
    location: package mypk
            demo = (mypk.Demo) pageContext.getAttribute("demo", PageContext.SESSION_SCOPE);
                        ^An error occurred at line: 10 in the jsp file: /ub.jspGenerated servlet error:
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\ub_jsp.java:46: cannot resolve symbol
    symbol  : class Demo 
    location: package mypk
              demo = new mypk.Demo();
      

  7.   

    这些错误
    type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 10 in the jsp file: /ub.jspGenerated servlet error:
        [javac] Compiling 1 source fileC:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\ub_jsp.java:42: cannot resolve symbol
    symbol  : class Demo 
    location: class org.apache.jsp.ub_jsp
          Demo demo = null;
          ^
    An error occurred at line: 10 in the jsp file: /ub.jspGenerated servlet error:
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\ub_jsp.java:44: cannot resolve symbol
    symbol  : class Demo 
    location: class org.apache.jsp.ub_jsp
            demo = (Demo) pageContext.getAttribute("demo", PageContext.SESSION_SCOPE);
                    
    An error occurred at line: 10 in the jsp file: /ub.jspGenerated servlet error:
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\ub_jsp.java:46: cannot resolve symbol
    symbol  : class Demo 
    location: class org.apache.jsp.ub_jsp
              demo = new Demo();
                         ^
    3 errors
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:127)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
    org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:458)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:552)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      

  8.   

    通过javabean里的id可以直接调用Demo里的方法了,不用再去声明Demo demo = new Demo();了吧
      

  9.   

    对啊..以上是错误信息.
    我在jsp是这样调用的:
    <%@ page contentType="text/html; charset=GBK" %>
    <%@ page import="mypk.*"%>
    <html>
    <body>
    <jsp:useBean id="demo" class="Demo" scope="session" />
    </body>
    </html>