• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question from manning about jsp:useBean

 
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" />
<%}%>
<jsp:useBean id="address" class="AddressBean" scope="session" />
<jsp:getProperty name="address" property="street" />
</body></html>
Which of the following is true about the above code? (Select one)
a It will give translation-time errors.
b It will give compile-time errors.
c It may throw runtime exceptions.
d It will print the value of the street property.
Answer: a

i think the answer should be 'd' because there is a pair of bracket arround the first useBean directive.so it will not cause error.
but the answer is 'a', anyone tell me why?
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The answer a is correct because you can not use same id attribute value in a translation unit more that once in <jsp:useBean> tag.

Thanks
 
muthu kumaran
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I would like to know, what sort of errors would be caught during transalation phase in a JSP life cycle.

Thanks
Muthu
 
singh santosh
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
the answer 'a' is correct ,which would be clear by following explanation..

when the above jsp file is translated into java file (servlet),then the java file will have two reference variable for AddressBean with the same identifier 'address' in the same scope which gives the error.

regards
-santosh

SCJP1.4(96%)
SCWCD --preparing
[ February 23, 2006: Message edited by: singh santosh ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic