aspose file tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes please solve head first scwcd problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "please solve head first scwcd problem" Watch "please solve head first scwcd problem" New topic

please solve head first scwcd problem

amit karn

Joined: Feb 02, 2010
Posts: 8
please help me

head fist jsp and servlet 2nd edition book

page no: 358

Question is :

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 is 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 each of the three different servlet code examples. (The answer is given at the page no : 420)

foo.Person p = new foo.Employee();
request.setAttribute(“person”, p);

answer 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.

my prob :

sinch the "person" attribute already exists in request scope that is set by servlet code.
then why it will fail at request time.

but why <jsp:useBean> tag won't work.

i have studied in page no : 356 of 2nd edition head first jsp & servlet book that
heading using type without class
if the persn attribute already exists in that scope
it works perpectly
if the person attribute does not exist in that scope
then java.lang.InstantiationException: bean person not fund within socpe

please explain. why this discrepancy happens.

it shoud work why fail at request time.

scjp 1.6(91%) , scwcd 1.5 (95%)
Ankit Garg

Joined: Aug 03, 2008
Posts: 9327

This is an error in the book, checkout the errata of the book for more errors in the book...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: please solve head first scwcd problem