aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Is this an error in HFSJ ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Is this an error in HFSJ ??" Watch "Is this an error in HFSJ ??" New topic
Author

Is this an error in HFSJ ??

Vikrant Pandit
Ranch Hand

Joined: Mar 27, 2006
Posts: 245
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 ]

Vikrant Pandit
Srikanth shetty Nukala
Greenhorn

Joined: Apr 07, 2006
Posts: 20
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...



Regards,<br />SCJA<br />SCJP 1.4<br />SCWCD 1.4<br />SCBCD or SCEA - coming soon!
Vikrant Pandit
Ranch Hand

Joined: Mar 27, 2006
Posts: 245
Hi Ranchers ..


Please provide some inputs regarding this ... Your help will be appreciated..
Aleksander Zielinski
Ranch Hand

Joined: Nov 11, 2005
Posts: 127
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

Joined: Jan 13, 2006
Posts: 136
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

Joined: Mar 27, 2006
Posts: 245
Hi,

I am not sure if PageContext.findAttribute() is used to locate beans instances when we use <jsp:useBean ....
singh santosh
Ranch Hand

Joined: Jan 13, 2006
Posts: 136
hi,
I hope this link will help clarifying ur doubt

regards
-santosh
Jayashree Mohan
Ranch Hand

Joined: Nov 23, 2005
Posts: 37
You can have a look at this link

http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is this an error in HFSJ ??