Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock question

 
Grace Yang
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following code:
<html><body>
<%{%>
<jsp:useBean id="address" class="AddressBean" scope="session" />
<%}%>
//1
</body></html>
Which of the following can be placed at line //1 above to print the value of the street property? (Select one)
a <jsp:getProperty name="address" property="street" />
b <% out.print(address.getStreet()); %>
c <%= address.getStreet() %>
d <%= ((AddressBean)session.getAttribute("address")).getStreet() %>
e None of the above; the bean is nonexistent at this point.

Answer: d

I think the Answer should be A.
 
Grace Yang
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I tried both A and D should work.

I am running Tomcat 5.5.1.7.

I found a very annoying cashing problem in the browser even I delete them from Tool options menu.

When I refresh the page after change my code, some times the page displays result, sometimes displays the errors , which really confuses me when I try to practise exercise.

Anybody run into this kind of problem?

Thanks
 
ping zhang
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right. I got the same result as try it.

And anther question, what's the difference when use the <useBean> in the <% %> block?
[ May 27, 2007: Message edited by: ping zhang ]
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

As seen in the code , the address object is set on the session. The 'address' vatiable as it is is local to the block in between <%{%> and <%}%>. Hence options b and c do not compile as 'address' variable is unknown outside the block. Option 'd' is correct because here we are explicitely fetching the object from session object and then using it. Option 'a' is correct too as jsp:getProperty is able to find the mentioned bean 'address' in the session scope. Option e is wrong for obvious reasons as a,d are correct.
 
ping zhang
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, the explanation is very clear.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic