1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Java Beans - useBeans servlets fail to find class name

Discussion in 'HTML, Graphics & Programming' started by sharingan_sasuk, 31 Jan 2006.

  1. sharingan_sasuk

    Wise Guy

    Joined: 8 Apr 2004

    Posts: 2,054

    I have apache running with tomcat apache for java and jsp stuff. I have changed the root path of the tomcat apache to a particular place in my hdd so that the program file is completely away from the development file.

    Ok, basically I am trying to do a useBean to call a servlet. I have nick this code from the web, as a tutorial to test it out. It can be found at this address...

    http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-JSP.html#Section8.2

    So I created to files, one called BeanTest.jsp and the code is as follows.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE>Reusing JavaBeans in JSP</TITLE>
    <LINK REL=STYLESHEET
    HREF="My-Style-Sheet.css"
    TYPE="text/css">
    </HEAD>

    <BODY>

    <CENTER>
    <TABLE BORDER=5>
    <TR><TH CLASS="TITLE">
    Reusing JavaBeans in JSP</TABLE>
    </CENTER>
    <P>

    <jsp:useBean id="test" class="hall.SimpleBean" />
    <jsp:setProperty name="test"
    property="message"
    value="Hello WWW" />

    <H1>Message: <I>
    <jsp:getProperty name="test" property="message" />
    </I></H1>

    </BODY>
    </HTML>



    and the second one called SimpleBean.java and code

    Code:
    package hall;

    public class SimpleBean {
    private String message = "No message specified";

    public String getMessage() {
    return(message);
    }

    public void setMessage(String message) {
    this.message = message;
    }
    }



    I compile the above code it creates SimpleBean.class
    I created a new folder in the same location as the three files created called classes. In there I created another folder called hall and in that placed the SimpleBean.java since I have read on the net that this is where class files should be kept.

    WHen I use http://localhost/BeanText.jsp I get this error message...

    HTTP Status 500 -

    type Exception report

    message

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

    exception

    org.apache.jasper.JasperException: /BeanTest.jsp(19,0) The value for the useBean class attribute hall.SimpleBean is invalid.
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
    org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1223)
    org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    org.apache.jasper.compiler.Generator.generate(Generator.java:3284)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:189)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


    Looking at the above, it looks like the class SimpleBean cannot be found. I have tried lots of ways in which to solve this and nothing is working, so I resort to this forum to help me. So if anyone knows what is wrong, can you please reply me as soon as possible. Thanks