• Post Reply Bookmark Topic Watch Topic
  • New Topic

please solve head first scwcd problem  RSS feed

Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me

head fist jsp and servlet 2nd edition book

page no: 358

Question is :

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 is 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 each of the three different servlet code examples. (The answer is given at the page no : 420)

foo.Person p = new foo.Employee();
request.setAttribute(“person”, p);

answer 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.

my prob :

sinch the "person" attribute already exists in request scope that is set by servlet code.
then why it will fail at request time.

but why <jsp:useBean> tag won't work.

i have studied in page no : 356 of 2nd edition head first jsp & servlet book that
heading using type without class
if the persn attribute already exists in that scope
it works perpectly
if the person attribute does not exist in that scope
then java.lang.InstantiationException: bean person not fund within socpe

please explain. why this discrepancy happens.

it shoud work why fail at request time.
Posts: 9610
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an error in the book, checkout the errata of the book for more errors in the book...
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!