wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Question from HF second edition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Question from HF second edition" Watch "Question from HF second edition" New topic
Author

Question from HF second edition

Tyronne Fernando
Ranch Hand

Joined: May 11, 2008
Posts: 50
Hi,

I am not sure whether this is posted here or not. The following question is from Head First Servlets and JSP second edition page 358.

----------------------------------------------------------------------

Look at this standard action:

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

Name is: <jsp:getProperty name=�person� property=�name� />

Now imagine that a servlet does some work and then forwards
the request to the JSP that has the code above.
Figure out what the JSP code above would do for the
following servlet code example.

What happens if the servlet code looks like:

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

----------------------------------------------------------------------

The answer given in the example is:

----------------------------------------------------------------------

FAILS at request time! The �person� attribute is stored at request
scope, so the <jsp:useBean > tag won�t work since it specifies only a
type. The Container KNOWS that if you have only a type specified,
there MUST be an existing bean attribute of that name and scope.

----------------------------------------------------------------------

I thought it will print "Name is: Evan". Is the answer is not correct in the book? I am not sure why it will fail as there will be a request attribute. Can someone please explain? Thanks heaps.
Sarat Koduri
Ranch Hand

Joined: Jul 08, 2008
Posts: 83
Fernando.. would you please confirm.. is this the code they have given..


i gues.. they have given.. like this..

because in this case as you might know the bean will be looking for page scope only....
Tyronne Fernando
Ranch Hand

Joined: May 11, 2008
Posts: 50
Thanks for the quick reply. The book has given like below with the scope:

<jsp:useBean id=�person� type=�foo.Employee� scope=�request� >
John Pearson
Ranch Hand

Joined: Oct 19, 2007
Posts: 51
I couldn't see any problem with the code as you listed it, so I wrote a quick test app just to see what it did. It worked just fine! Maybe it is a mistake in the wording of the question.
Rufus Addis
Ranch Hand

Joined: Aug 21, 2008
Posts: 83
This has cropped up a few times. IMHO it's an error in the 2nd edition and is mentioned in the unconfirmed section of the Errata. See the following thread:

http://www.coderanch.com/t/178060/java-Web-Component-SCWCD/certification/HFSJ-Container-page

Rufus.
Tyronne Fernando
Ranch Hand

Joined: May 11, 2008
Posts: 50
Thanks guys
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question from HF second edition