• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean tag question

 
Bhupendra Khabrani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is an example in Head First(1.4 ver book) which mentions pg 356 (chap 8-be a container)
in 3rd option that
request.setAttribute("person",p) will enable
<jsp:useBean id="person" type="foo.Employee"/>
<jsp:getProperty name="person" property="name"/>

this to give correctly the name set even though as we know that if

scope

is not mentioned it defaults to page. here it should default to page and since the attribute

person

is set in request scope it should not be able to find the bean.

please help me understand if there is flaw in my understanding!!??
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If scope is not specified then it is the page scope. Since there is no attribute in with the name person in the page scope the container will try to create one in the page scope but since we didn't provide the class in this case the useBean will raise an exception.

for this to work you either need to specify the scope in useBean or the class.
 
Bhupendra Khabrani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah i too agree on the same thing Musab Al-Rawi.
But my point is that the same concept has been very much emphasized in the first scenario on the same(pls refer the question at top) page of HFJS 1.4, that if the bean person is not there in the request scope then it would fail at run time.

even then how could this mistake be done in the book ...?

thanks
Bhupen
[ May 27, 2008: Message edited by: Bhupendra Khabrani ]
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you checked in errata regarding this ?

http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed
[ May 27, 2008: Message edited by: Garla Ravi ]
 
Bhupendra Khabrani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ravi,
on closely looking i could find the same in the errata.

thanks for help guys.
Bhupen
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic