In HFSJ 1.5 page 420 I have a problem.
It says,
<
jsp:useBean id="person" type="foo.Employee" scope="request">
<jsp:setProperty name="person" property="name" value="Fred" />
</jsp:useBean>
Name is: <jsp:getProperty name="person" property="name">
Following is what in the servlet,
foo.Person p=new foo.Employee();
p.setName("Evan");
request.setAttribute("person",p);
And following are the bean classes,
public class abstract Person(){
private
String name;
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
}
public class Employee extends Person{
// setEmpID and getEmpID methods
}
So what i understand is since the jsp:useBean only define type the body will not get execute. But it wont be a problem because in servlet we have already set a attribute.
And the servelt generated by compiled by the jsp will look like this probebly,
Employee person = null;
person = (Employee) _jspx_page_context.getAttribute("person", PageContext.REQUEST_SCOPE);
if (person == null){
throw new java.lang.InstantiationException("bean person not found within scope");
}
So my point isnt the "_jspx_page_context.getAttribute("person", PageContext.REQUEST_SCOPE);" will return a object (
with refernce type Person and object type Employee) becuse we set it in our servlet (
both have request scope i mean in servlet and in jsp)and it will be cast in to Employee and person variable here will be initialized.
So Evan should have print.
But the book says, Fail at request time.
(me : what is exactly this request time..is it like after having RequestDispatcher we forward(request,response) to the JSP time??) The "person" attribute is stored at request time so the jsp:useBean tag wont work since it specify only the type (
me : here im having a problem with this statement it should be jsp:setProperty tag wont work not jsp:useBean??) and it also saying The container knows that if you have only a type specified there must be an existing bean attribute of that name and scope(
me: ofcourse we have set a attribute in the servlet with person name and request scope so there shouldn't have a problem??)
please explain me what is wrong or if I have understand the concept wrong..im stuck with this concept.
Thank you.