• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp:useBean doubt?

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,

On page 416 of HFSJ, it says that the first option fails to compile, but the third option compiles fine. For the first one, I can understand the reason but why for the 3rd one, it works fine?? Any help on this would be of real help to me to understand it better.

Thanks in advance!
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you quote the question please
 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check Head First Servlets and Jsp Errata
You will get correct answer.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,

<jsp:useBean id="person" type="foo.Employee">
<jsp:setProperty name="person" property="name" value="Fred"/>
</jsp:useBean>

Name is <jsp:getProperty name="person" property="name"/>

What happens if the servlet code looks like:

foo.Person p = new foo.Employee();
p.setName("Evan");
request.setAttribute("person", p);

The above one fails at request time, but whereas

foo.Employee p = new foo.Employee();
p.setName("Evan");
request.setAttribute("person", p);

This works fine and prints Evan! How? We are only specifying the type? aren't we??

Also, if I comment out all the p.setName("Evan") in all the 2 cases above, then the o/p will be Fred right??
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gowher,

Where can I get the errata for the HFSJ? Please help!
 
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael.
reply
    Bookmark Topic Watch Topic
  • New Topic