wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HF page 416 answer for question 3  might be wrong Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HF page 416 answer for question 3  might be wrong" Watch "HF page 416 answer for question 3  might be wrong" New topic
Author

HF page 416 answer for question 3 might be wrong

Raju Sri
Ranch Hand

Joined: Mar 10, 2004
Posts: 108
Hi ranchers,

In HF book page 416 question 3 specified as it works fine and prints out "Evan". I think it won't work because Servlet is setting person object in the REQUEST SCOPE and JSP is looking in the PAGE SCOPE(as it not specified any scope).

The JSP page is accessing the person bean in PAGE scope which is default if not specified.
#######################
<jsp:useBean id="person" type="foo.Employee">
<jsp:setProperty name="person" property="name" value="Fred"/>
</jsp:useBean>
Name is:<jsp:getProperty name="person" property="name"/>
########################

The Servlet code in question 3 is like below which is setting in REQUEST scope.
#################################
foo.Employee p = new foo.Employee();
p.setName("Evan");
request.setAttribute("person",p);
#################################


I tested this code and it failed as I expected.So question 3 will work only if JSP specifies scope of person as REQUEST like below.
**************************
<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"/>
**************************
Can somebody confirm this for me?

Cheers
Raju
[ September 26, 2004: Message edited by: raju srinivasa ]

SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3<br />SCDJWS 1.4
Raju Sri
Ranch Hand

Joined: Mar 10, 2004
Posts: 108
Hi ,

I have just seen in another thread this problem already posted and Kathy replied to that.
http://www.coderanch.com/t/168124/java-Web-Component-SCWCD/certification/jsp-usebean

Cheers
Raju
 
wood burning stoves
 
subject: HF page 416 answer for question 3 might be wrong
 
Similar Threads
<jsp:useBean> K&B Standard Action Question on page 358.
jsp:useBean standard action doubt
Is this an error in HFSJ ??
Bean related exercise question
Question to Kathy