Re: JSP/Bean basics

From: fishfry (BLOCKSPAMfishfry_at_your-mailbox.com)
Date: 07/28/04


Date: Wed, 28 Jul 2004 05:25:00 GMT

In article <MPG.1b7010f31af9eb86989ff8@nntp.lucent.com>,
 kaeli <tiny_one@NOSPAM.comcast.net> wrote:

> In article <BLOCKSPAMfishfry-79D76A.00214327072004@netnews.comcast.net>,
> BLOCKSPAMfishfry@your-mailbox.com enlightened us with...
> > I'm just learning how to use JSP's to invoke simple Java Beans. The
> > concepts are clear but I can't get my example to work. The problem is
> > that my JSP can't find my Bean class.
> >
>
> It has to be in a package.
> Did you package the beans?
>
> The path to the package must be in the classpath of the server in some way.
> You mention that you are using Tomcat. Tomcat uses a web.xml file and the
> directories have to be set up a certain way. I use IPlanet, so I can't say if
> it's exactly the same, but my beans are in WEB-INF/classes/beanPackageName/

Thanks much. I'm getting close. I know whatever I'm doing wrong must be
totally lame. Here's my code.

Bean:

package fooBeanPackage;

public class FooBean {
    int x = 47;
    String s = "Hello World";

    public FooBean() {
    }

    int getX() {
        return x;
    }

    void setX(int val) {
        x = val;
    }

    String getS() {
        return s;
    }

    void setS(String val) {
        s = val;
    }
} // FooBean

And now here's the relevant part of my JSP:

<jsp:useBean id = "foo" class = "fooBeanPackage.FooBean" scope = "page"
/>

<p>Here is data from FooBean:<br>

<jsp:getProperty name = "foo"
                 property = "x"
/>

After compiling FooBean, I put the class file in classes/fooBeanPackage.

Now when I run the JSP I get:

org.apache.jasper.JasperException: Cannot find any information on
property 'x' in a bean of type 'fooBeanPackage.FooBean'
        
org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibra
ry.java:883)
        
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java
:1055)
        
org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1079)
        org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2180)
        org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2230)
        org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2236)
        org.apache.jasper.compiler.Node$Root.accept(Node.java:485)
        org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2180)
        
org.apache.jasper.compiler.Generator.generate(Generator.java:3255)
        
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:277)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:456)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
        
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.jav
a:553)
        
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.jav
a:291)
        
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:856)



Relevant Pages

  • Re: JSP/Bean basics
    ... >> that my JSP can't find my Bean class. ... > It has to be in a package. ... public class FooBean { ... And now here's the relevant part of my JSP: ...
    (comp.lang.java.help)
  • Re: my first bean (tomcat)
    ... I believe I have a problem because the package name of my Bean ... I have found this by including into my webapp a Bean I ... Put the bean's class file in the webapp's WEB-INF/classes directory, or jar it up and put the jar in the webapp's WEB-INF/lib directory. ...
    (comp.lang.java.programmer)
  • Re: I was good this year!!!
    ... >>> flannel lined jeans yesterday. ... They were in the mailbox and said LL ... >>> Bean all over the package. ...
    (rec.food.cooking)
  • Re: my first bean (tomcat)
    ... Hello John (or anyone else who happens, like me, to be working on ... I believe I have a problem because the package name of my Bean ... I have found this by including into my webapp a Bean I ... Prev by Date: ...
    (comp.lang.java.programmer)
  • Java Beans & Packages
    ... I have a bean, which I put into a package containing servlets for my web ... When I isolated the exact same bean code into a new package, ... In fact thats where I got the idea to isolate the bean into ...
    (comp.lang.java.help)