I've had problems with similar examples in the same book.  It's a
scope problem, possibly a bug.  If you examine the source code of the
generated servlet, you'll probably find that the 'db =
(DbProdBean)i.next();' line in the scriptlet is accessing a local variable
'db', while the <jsp:getProperty name="db" property="shortDescription" />
action is trying to access an attribute 'employee' of either the request or
the pageContext object.

        If you want to continue using bean tags, try replacing

      db = (DbProdBean)i.next();

with something like:

        pageContext.setAttribute("db", (DbProdBean)i.next(),
pageContext.REQUEST_SCOPE);

        What are you using for a server?  This has been happening to me
under Tomcat 3.1.


-----Original Message-----
From: John Bell [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 11, 2000 6:50 AM
Subject: Re: jsp:getProperty


I am trying to display results retrieved from a database. (using model from
Fields book)
The debug shows that the prodList Vector is sucessfully populated.

else if (cmd.equals( "cat3prod")){
        DbProdBean db;
        ProdUtils utils = new ProdUtils();
        Vector prodList = utils.fetchAll(index);
        Iterator i = prodList.iterator();
        // debug
        while (i.hasNext()) {
                db = (DbProdBean)i.next();
                System.err.println("in Ctl  :" + db.getShortDescription()
+":");
                System.err.println("in Ctl  :" + db.getUnitCost() +":");
        }
         // end debug
         request.setAttribute("prodList", prodList);
        System.err.println("off to JSP size is " +prodList.size() );
        tocat3prodpage.forward(request, response);
}

but in the JSP page  I get as the correct number of 'hello's but no
shortDescriptions etc.
What am I doing wrong?

<%@ page language="java" import="java.sql.*, java.util.*%>
<jsp:useBean id="db" scope="request" class="DbProdBean" />
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body>

<%
 Vector v  = (Vector)request.getAttribute("prodList");
   Iterator i = v.iterator();
 while (i.hasNext()) {
      db = (DbProdBean)i.next();
%>
<b>
hello
<jsp:getProperty name="db" property="shortDescription" />
</b><br>

<b>
<jsp:getProperty name="db" property="unitCost"/>
</b><br>
<jsp:getProperty name="db" property="prevUnitCost"/>

<%    }%>

</body>
</html>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to