aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ: Be the Container: page 358 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 "HFSJ: Be the Container: page 358" Watch "HFSJ: Be the Container: page 358" New topic
Author

HFSJ: Be the Container: page 358

Michael Vargenstien
Ranch Hand

Joined: Jan 27, 2007
Posts: 61
Hello,

This book rocks...I mean, its like crack. I can't get enough... but I have a question which I don't really understand from the book. I'm tempted to believe its wrong...but I could be too because they're certified and I'm still posting.

The question is on page 358:
You have JSP Code:

It basically says what happens if the servlet code looks like this:



now, according to the book, it blows up...but here's the thing, wouldn't the variable be on the existing page since the jsp being specified is requesting a scope of request type and this is exactly the same scope that is being set in the attribute of the calling servlet BEFORE it forwards to the jsp?

Am I too interprete page 356 which states Result if the person attribute already exists in "page" scope strictly? Or is it...wrong?
Sarat Koduri
Ranch Hand

Joined: Jul 08, 2008
Posts: 83
Michael ... as per the code you have given..



when you give the type alone,it means.. the container just looks for the available bean object and its clear ofcourse.. the point here is if we do not specify the class type and by chance if the bean does not exist in the scope .. the container has no way to know which object reference we need to assign since there is no class..


the above code you have provided is not corret in this context.. and which hfsj book are you using.. hfsj 2nd edition .. ?? page 358 has different information.. dude... i know i have answered only partially ..
Michael Vargenstien
Ranch Hand

Joined: Jan 27, 2007
Posts: 61
Thanks for your reply. Yeah, this is the 2nd edition (Updated for EE5) version. The best way to prove this is probably just do it on my own (write an application) and post the results.

Do you think they will let met use the compiler for the test?
Sarat Koduri
Ranch Hand

Joined: Jul 08, 2008
Posts: 83
he he he... .. ya even i do not i understand why don't they allow us to use the compiler in the exam. ofcourse if we know the code only we can write.. and the objective of the exam is to prove that we know the coding..

Sun should consider this..option of allowing people to use compiler during the exam. ..
Rufus Addis
Ranch Hand

Joined: Aug 21, 2008
Posts: 83
FWIW this is mentioned a couple of times in the "unconfirmed" errata pg420 for the 2nd edition:

http://oreilly.com/catalog/9780596516680/errata/

I agree with the comments, it should work, and when I tried it, it appeared to work!

Worth checking the rest of the errata, in particular the mock section IMHO!

Rufus.
Lee Kian Giap
Ranch Hand

Joined: Jan 23, 2008
Posts: 213
Hi ,

can anyone give a confirm answer regarding this , no final conclusion since few years ?

my understanding is that

====

from the servlet code , it is a polymorphic reference

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

so for the standard action , it will only work with this
<jsp:useBean id="person" type="foo.Person" class="foo.Employee" scope="request" />

====

if you want this to work
<jsp:useBean id="person" type="foo.Employee" scope="request" />

for the servlet code, you need to have the same reference type and object type
foo.Employee e = new foo.Employee();
p.setName("Evan");
request.setAttribute("person", e);

====

can anyone clarify this ?


SCJP 6, SCWCD 5, SCBCD 5
Harvinder Thakur
Ranch Hand

Joined: Jun 10, 2008
Posts: 231
from the servlet code , it is a polymorphic reference

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

so for the standard action , it will only work with this
<jsp:useBean id="person" type="foo.Person" class="foo.Employee" scope="request" />


The above will also work with following:

<jsp:useBean id="person" type="foo.Person" scope="request" />

AND

<jsp:useBean id="person" type="foo.Employee" scope="request" />

if only the "type" attribute is mentioned then the attribute with the same id which in our case is "person" should exist in the "request" scope.

It seems the web container does a check of something like:

if ( person attribute exists in request scope
&& [object referred by attribute "person" stored in "request" scope] instanceof
[type= say "foo.Employee"]
)
THEN
return the reference to that object referred to by person attribute
ELSE
throw an exception


thanks
Harvinder
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HFSJ: Be the Container: page 358