回 帖 发 新 帖 刷新版面

主题:新手请教:jsp调用javaBean!

我用的是jdk1.4,tomcat4.1;
jsp文件放在  C:\tomcat\webapps\ROOT\myapp\test   目录下;
----
<BODY>
<jsp:useBean id="hellobean" scope="application" class="test.helloworld"/>
<%=hellobean.getHi()%>
<hr>
<%
  hellobean.name="JSP";
out.print(hellobean.getHi());
%>
</BODY>
----
java 文件编译后 helloworld.class放在
C:\tomcat\webapps\ROOT\myapp\WEB-INF\classes\test

package test;

public class  helloworld
{
    public String name="My first bean";
    public String getHi()
    {
        return "Hello from"+name;
    }
}

编译提示:
package test don't exist;
--------------------------
.jsp文件和.calss文件应放哪?




回复列表 (共3个回复)

沙发

在test目录下新建一个WEB-INF文件夹,在文件加里再新建一个class文件夹,将class文件放入,jsp文件放入test文件夹,运行即可

板凳

或者将jsp文件放在myapp下,class文件不动,也可以

3 楼

我用的是XP系统!

.jsp放在C:\tomcat\webapps\ROOT\myapp下;
.class放在C:\tomcat\webapps\ROOT\myapp\WEB-INF\classes\test下,

还是不行!错误为:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 6 in the jsp file: /myapp/hibean.jsp

Generated servlet error:
    [javac] Compiling 1 source file

C:\tomcat\work\Standalone\localhost\_\myapp\hibean_jsp.java:48: package test does not exist
      test.helloworld hellobean = null;
          ^



An error occurred at line: 6 in the jsp file: /myapp/hibean.jsp

Generated servlet error:
C:\tomcat\work\Standalone\localhost\_\myapp\hibean_jsp.java:50: package test does not exist
        hellobean = (test.helloworld) pageContext.getAttribute("hellobean", PageContext.APPLICATION_SCOPE);
                         ^



An error occurred at line: 6 in the jsp file: /myapp/hibean.jsp

Generated servlet error:
C:\tomcat\work\Standalone\localhost\_\myapp\hibean_jsp.java:53: package test does not exist
            hellobean = (test.helloworld) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "test.helloworld");
                             ^
3 errors

请指点!

我来回复

您尚未登录,请登录后再回复。点此登录或注册