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

useBean directive,which is true, and why?

 
air lulu
Ranch Hand
Posts: 42
  • 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.
 
air lulu
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i try it in tomcat4.1.
answer a,d will also print the value of street.
 
kapil munjal
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a <jsp:getProperty name="address" property="street" />
b <% out.print(address.getStreet()); %>
c <%= address.getStreet() %>
d <%= ((AddressBean)session.getAttribute("address")).getStreet() %>


I think you are right...all these should return the value...

Can someone else clarify???
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

All answers if used correctly will provide a result.
However, at the line marked '//1' you are outside the enclosing scope of the scriptlet



therefore b and c will NOT work but will cause errors.

If the code was along the lines of


This will work (provided I changed all the names back correctly because my example used different bean name and properties)

also if the question was changed to be this the all four answers would again be correct



HTH

Mat
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic