Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean doubt?

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC 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!
 
VijayKumar Sivagnanam
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you quote the question please
 
Gowher Naik
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: 10128
3
Eclipse IDE Mac PPC 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: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gowher,

Where can I get the errata for the HFSJ? Please help!
 
Micheal John
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: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic