my dog learned polymorphism
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ Page 356, Page 416 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFSJ Page 356, Page 416" Watch "HFSJ Page 356, Page 416" New topic

HFSJ Page 356, Page 416

Fola Fadairo
Ranch Hand

Joined: Feb 16, 2004
Posts: 35


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

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();
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 ]
Kamal Agrawal

Joined: May 25, 2007
Posts: 14
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" />

Name is: <jsp:getProperty name="person" property="name" />
I agree. Here's the link:
subject: HFSJ Page 356, Page 416
It's not a secret anymore!