• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

please solve head first scwcd problem

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
p.setName(“Evan”);
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
and
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.
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an error in the book, checkout the errata of the book for more errors in the book...
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic