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

Is this an error in HFSJ ??

 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

Please refer Pg 356 ( Be the container )

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


What would happen in JSP if the servlet code looks like this

Person is the superclass of Employee

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

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

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

My basic question is that since there is no scope specified in JSP , page is the default scope. But in all the 3 servlet snippets we are placing the attribute in request scope.

So in all the three cases JSP will not be able to find the bean. But the answer in the book says something else.


Any thoughts ??


[ April 27, 2006: Message edited by: Vivek Pandey ]
 
Srikanth shetty Nukala
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i had the same thought, but the answer says something else so there might be a chance that useBean also looks through all the scopes (searches), but as far as i remember if no scope is specified the default will be "page" scope.

would be good if someone can clarify...

 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers ..


Please provide some inputs regarding this ... Your help will be appreciated..
 
Aleksander Zielinski
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it will not find the bean. No scope specified in <jsp:useBean> means look in page scope only. Because there's no class attribute specified, just type, what you get is an exception.
 
singh santosh
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,

So in all the three cases JSP will not be able to find the bean. But the answer in the book says something else.


the jsp will find the bean using PageContext.findAttribute("person") which looks into all the scopes [from page scope >....> to application scope].

please look into Tomcat 5.5\work\Catalina\localhost\urApplication\org\apache\jsp\urJspFile_jsp.java for the genearated java file for the jsp file.

U can find PageContext.findAttribute("person") in that java file.
hope this helps

regards

-santosh
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am not sure if PageContext.findAttribute() is used to locate beans instances when we use <jsp:useBean ....
 
singh santosh
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I hope this link will help clarifying ur doubt

regards
-santosh
 
Jayashree Mohan
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have a look at this link

http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic