• Post Reply Bookmark Topic Watch Topic
  • New Topic

doubt in a mock question  RSS feed

pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 3. 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 later. )

<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/>

The code for Account.java is:-----

package com.enthuware.jwebplus;

public class Account {

private int acctno;
private String name;
private double balance;

public Account() {

public Account(int accountNumber, String name, double balance){
this.acctno = accountNumber; this.name = name; this.balance = balance;

public int getAcctno() {
return acctno;

public void setAcctno(int acctno) {
this.acctno = acctno;

public String getName() {
return name;

public void setName(String name) {
this.name = name;

public double getBalance() {
return balance;

public void setBalance(double balance) {
this.balance = balance;


OPTIONS are given:
1.Nothing. No name will be printed.
2. Bobby
4.None of the above is correct.

My answer is 4. because answer should be Bob which is not given in options
but answer given for this question is 3.crazy.I think it is wrong

Source is Enthuware kit
[ May 31, 2008: Message edited by: pradeep singh ]
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
answer is wrong.
It should be option 4 or Bob
Paul Anilprem
Enthuware Software Support
Ranch Foreman
Posts: 3991
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct. The answer has been mistakenly set. It should be Bob. The following explanation provided with the question clears it up.

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 have executed the body of the useBean tag. In the given question, the bean is already there. So no new bean is created and 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

[ June 01, 2008: Message edited by: Paul Anil ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!