File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jsp:useBean possible error in HFSJ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jsp:useBean possible error in HFSJ" Watch "jsp:useBean possible error in HFSJ" New topic

jsp:useBean possible error in HFSJ

thomas jacob
Ranch Hand

Joined: May 19, 2005
Posts: 91
The exercise in the HFSJ book is as follows

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

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

Question: What will the output for this be
<jsp:getProperty name="person" property="name" />

Answer in Book: The book states that this work fine and prints out Evan. The code inside the body of <jsp:useBean> will never run, since we specified a type without class.

I FEEL: IT SHOULD FAIL AT REQUEST TIME cos when the scope is not mentioned in the useBean tag, so it defaults to the page scope. When only the type is mentioned in the useBean tag there should be an existing attribute bean with the same name and scope. Here the scope is not same. The attribute bean exists in the request scope. The tag is searching in the page scope

The book anyhow contradicts the answer by saying when only the type is mentioned in the useBean tag there should be an existing attribute bean with the same name and scope


Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

Yep this thought came across my head but i brushed it aside and and continued with the book. The scope attribute should have mentioned "request".

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Doyle Matt
Ranch Hand

Joined: Jul 05, 2004
Posts: 76
Yup Thomas, you are correct. Tried it out and I got an exception

SCJP 1.4
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
This is where the head first gets clumsy
i have borken my head over this page as it has got an errata
but even after this the THING isnt yet clear, so i too BRUSHED the page aside and continued further

SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
It's there in the errata

Dilshan Edirisuriya SCJP1.4, SCWCD1.4, SCBCD 5
I agree. Here's the link:
subject: jsp:useBean possible error in HFSJ
It's not a secret anymore!