JSP和Beans:放置类文件的位置

时间:2012-12-24 06:33:47

标签: jsp javabeans

我是jsp的新手,有一个关于jsp和bean的问题。

我创建了以下java文件作为bean,编译它并将java和类文件保存在 C:\ Program Files \ Apache Software Foundation \ Tomcat 7.0 \ webapps \ jspfiles \ WEB-INF \ classes < / em>文件夹:

package test;

public class Hello
{
private String str;

    public void setStr (String value)
    {
        str = value;
    }

    public String getStr ()
    {
        return str;
    }
}

我的jsp文件test.jsp,包含以下代码,位于 C:\ Program Files \ Apache Software Foundation \ Tomcat 7.0 \ webapps \ jspfiles 文件夹中。

<!DOCTYPE html>
<%@ page contentType="text/html;charset=windows-1252"%>

<jsp:useBean id="test" class="test.Hello" scope="session"/>

当我打开test.jsp文件(http:// localhost:8082 / jspfiles / test.jsp)时,我收到此错误:

HTTP Status 500 - /test.jsp (line: 4, column: 0) The value for the useBean class attribute test.Hello is invalid.

type Exception report

message /test.jsp (line: 4, column: 0) The value for the useBean class attribute test.Hello is invalid.

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

exception

org.apache.jasper.JasperException: /test.jsp (line: 4, column: 0) The value for the useBean class attribute test.Hello is invalid.
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:408)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:149)
    org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1234)
    org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1182)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:475)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    org.apache.jasper.compiler.Generator.generate(Generator.java:3490)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:250)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.34 logs.

上面有什么问题?

1 个答案:

答案 0 :(得分:1)

你有一个名为test的软件包很好。您的类文件应位于与包结构匹配的目录中。在这种情况下,在名为classes的{​​{1}}下创建一个目录,并在其中放置test

Hello.class