This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

jsp:useBean doubt?

 
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
can you quote the question please
 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check Head First Servlets and Jsp Errata
You will get correct answer.
 
Joe Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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 Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed
 
Joe Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael.
 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic