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

Standard Actions

 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will the following jsp page print for the name of the Account if the page is access through a url containing name=crazy as the query string?

(The code for Account.java is given in exhibit. )

<html>
<body>
<h1>Simple Bean Usage</h1>
<%
pageContext.setAttribute("account", new com.enthuware.jwebplus.Account(1, "Bob", 1000.0));
%>

Account Name is :
<jsp:useBean id="account" class="com.enthuware.jwebplus.Account">
<jsp:setProperty name="account" property="name" param="name/>
</jsp:useBean>
<%=account.getName()%>
</body>
</html>


1.Nothing. No name will be printed.

2.Bobby

3.crazy

4.None of the above is correct.

The correct answer given is 3. But according to me the correct answer should be 4.

Even in the hint, it show's clearly the correct answer should be 4. But still they selected the answer 3.

This is from Enhtuware.

Please Advice.

Hint-Remember that the body of useBean tag is executed ONLY if the useBean tag instantiates a bean (as opposed to locate an existing bean). For example, had there been no prior creation of the bean, the useBean tag would have had to create/instantiate a new instance of the bean class and so it would execute the body of the useBean tag. In the given question, the bean is already there. So no new bean is created and so the body is ignored. Hence the setProperty tag will be ignored.

This is very nicely explained here: http://java.sun.com/products/jsp/tags/11/syntaxref11.fm14.html
 
Ali Khalfan
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be a trick


you're not instantiating a bean here...just an attribute, my guess is the body will be executed.

anyone?
 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new com.enthuware.jwebplus.Account(1, "Bob", 1000.0));

when we are doing new, we are actually instainting a bean.
 
Joy Mukherjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also think the correct answer is 4.

If any answers had Bobby then that would been the correct answer.
Since there is Bob and not bobby I think the correct answer is
4

Thanks and Regards
Joy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic