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

Whats the error???

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt in the following piece of code from HFSJ pg 356.

jsp code is.....

<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"/>


servlet code is........

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

Person is an abstract bean class n Employee extends it.

Now this code wudnt work. I want to know why... as far as i cud understand is as we have not mentioned the scope in useBean tag, by default it wud be page. In the servlet we have set the person attribute at request scope, so useBean wont find any attribute named person in page scope n thus give error.Am i understanding it correctly...If anyone can help???

Thanx in advance.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right.
Another consideration:
<jsp:setProperty> as used in this example will never be executed, also if you put your bean in page scope. It is only executed when a bean isn't in scope and you use the class or beanName attribute to create or load an istance of the bean.

Bye.
 
Bhavna Jharbade
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paolo thanx for the confirmation. But now if i have this code in my servlet wud it work......

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

The book says it will work but according to me it shud again not work because of the reason the earlier code didnt worked. What do u say???
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though you are setting attribute of the same type, the scope is different, so the useBean doesn't find the attribute. Also, only type is defined in usBean so no new object will be created. If you define the "scope" attribute to "request", you have to forward the same request from servlet code to target jsp.

Hope it help you.

Thanks
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bhavna,

The great HFSJ book also has errors. Thankfully there's an errata page...please consult it whenever you think the book is not making sense.

Here's the link:
http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed

Good luck,
Troy
 
Bhavna Jharbade
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Troy,
Thanx for the link it has cleared my doubt.

Thanx to others also for their help.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to confirm,

The example shown in Pg. 356 with


would NOT work. Isn't that the conclusion ?
 
Bhavna Jharbade
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes n the reason is same as is for the first piece of code.Its a mistake in the book.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic