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

jsp:useBean possible error in HFSJ

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The exercise in the HFSJ book is as follows

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

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

Question: What will the output for this be
<jsp:getProperty name="person" property="name" />

Answer in Book: The book states that this work fine and prints out Evan. The code inside the body of <jsp:useBean> will never run, since we specified a type without class.

I FEEL: IT SHOULD FAIL AT REQUEST TIME cos when the scope is not mentioned in the useBean tag, so it defaults to the page scope. When only the type is mentioned in the useBean tag there should be an existing attribute bean with the same name and scope. Here the scope is not same. The attribute bean exists in the request scope. The tag is searching in the page scope

The book anyhow contradicts the answer by saying when only the type is mentioned in the useBean tag there should be an existing attribute bean with the same name and scope

JAVARANCH GUYS PLEASE HELP....

Regards
Thomas
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep this thought came across my head but i brushed it aside and and continued with the book. The scope attribute should have mentioned "request".
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup Thomas, you are correct. Tried it out and I got an exception
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is where the head first gets clumsy
i have borken my head over this page as it has got an errata
but even after this the THING isnt yet clear, so i too BRUSHED the page aside and continued further
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's there in the errata

http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed
 
Something about .... going for a swim. With this tiny ad ...
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic