This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of TensorFlow 2.0 in Action and have Thushan Ganegedara on-line!
See this thread for details.
Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Standard Actions

 
Ranch Hand
Posts: 856
  • 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
 
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: 856
  • 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.
 
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
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic