0

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

我将以下 java 文件创建为 bean,对其进行编译并将 java 和类文件保存在C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\jspfiles\WEB-INF\classes文件夹中:

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.

上面有什么问题?

4

1 回答 1

1

你有一个test很好的包。您的类文件应位于与包结构匹配的目录中。在这种情况下,在 call 下创建一个目录classes并将test其放置Hello.class在其中。

WEB-INF/classes/test/Hello.class
于 2012-12-24T06:42:22.167 回答