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

Is this an error in HFSJ ??

 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers ..


Please provide some inputs regarding this ... Your help will be appreciated..
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I hope this link will help clarifying ur doubt

regards
-santosh
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can have a look at this link

http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed
 
Did you miss me? Did you miss this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic