0
votes

I am new to jsp, and a have a question regarding jsp and beans.

I created the following java file as a bean, compiled it and saved the java and the class file in C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\jspfiles\WEB-INF\classes folder:

package test;

public class Hello
{
private String str;

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

    public String getStr ()
    {
        return str;
    }
}

My jsp file, test.jsp, with the following code is in C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\jspfiles folder.

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

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

When I open the test.jsp file (http://localhost:8082/jspfiles/test.jsp), I get this error:

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.

What is wrong above?

1

1 Answers

1
votes

You have a package called test which is good. Your class files should be in a directory matching the package structure. In this case make a directory under classes called test and place Hello.class in there.

WEB-INF/classes/test/Hello.class