• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HFSJ Page 356, Page 416

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Question:

Be the Container. Figure out what the container would do for each of the three diffent servlet code examples.


Look at this standard action:


<jsp:useBean id = "person" type="foo.Employee" >
<jsp:setProperty name="person" property="name" value="Fred" />
</jsp:useBean>


Name is: <jsp:getProperty name="person" property="name" />


public abstract class Person{

private String name;

public String getName();
public void setName();

}


public class Employee extends Person {
//implentations of inherited methods.... getName() and setName()

private int empID;

public int getEmpID(){
return empID;
}


void setEmpID(int e) {
empID = e;
}

}


Servlet code example 3:
What happens if the servlet code looks like:

foo.Employee p = new foo.Employee();
p.setName("Evan");
request.setAttribute("person", p);

The answer says:
"This works fine, and prints out "Evan". Remember, the code INSIDE the body of <jsp:useBean> will NEVER run, since we specified a type without class."


In my opinion, the answer should be: (like the 1st servlet code, not shown here)
"FAILS at request time! The person attribute is stored at request scope, so the jsp:useBean> tag won't work since it specifies only a type. The Container knows that if you have only a type specified, there must be be an existing bean attribute of that name and scope."
[ June 05, 2007: Message edited by: Fola Fadairo ]
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right.
Default scope for jsp:useBean is Page not request.
So now the belwo code will run fine.

<jsp:useBean id = "person" type="util.Employee" scope="request">
<jsp:setProperty name="person" property="name" value="Fred" />
</jsp:useBean>


Name is: <jsp:getProperty name="person" property="name" />
<br>
 
My cellmate was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic