• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HF page 416 answer for question 3 might be wrong

 
Raju Sri
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Raju Sri
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic