Hi,
I am not sure whether this is posted here or not. The following question is from Head First
Servlets and
JSP second edition page 358.
----------------------------------------------------------------------
Look at this standard action:
<jsp:useBean id=�person� type=�foo.Employee� scope=�request� >
<jsp:setProperty name=�person� property=�name� value=�Fred� />
</jsp:useBean >
Name is: <jsp:getProperty name=�person� property=�name� />
Now imagine that a servlet does some work and then forwards
the request to the JSP that has the code above.
Figure out what the JSP code above would do for the
following servlet code example.
What happens if the servlet code looks like:
foo.Person p = new foo.Employee();
p.setName(�Evan�);
request.setAttribute(�person�, p);
----------------------------------------------------------------------
The answer given in the example is:
----------------------------------------------------------------------
FAILS at request time! The �person� attribute is stored at request
scope, so the <jsp:useBean > tag won�t work since it specifies only a
type. The Container KNOWS that if you have only a type specified,
there MUST be an existing bean attribute of that name and scope.
----------------------------------------------------------------------
I thought it will print "Name is: Evan". Is the answer is not correct in the book? I am not sure why it will fail as there will be a request attribute. Can someone please explain? Thanks heaps.