我是 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.
上面有什么问题?