In my earlier post i had asked abt a mistake from the book HF
servlets &
JSP(authors basham,kathy,bates).i did not get a reply.
Hope i get a reply from the author atleast for this:
In chapter8 from HF servlets & JSP there is an exercise named "Be the Container" which has the following question..
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" />
what would the above jsp evaluate to if the servlet code looks in the following three different ways?Assume that foo.Person is an abstract class and foo.Employee is a concrete class that extends foo.Person.
1.
foo.Person p= new foo.Employee();
p.setName("Evan");
request.setAttribute("person",p);
2.
foo.Person p = new foo.Person();
p.setName("Evan");
request.setAttribute("person",p);
3.
foo.Employee p = new foo.Employee();
p.setName("Evan");
request.setAttribute("person",p);
Answers given in the book were:
With the first servlet code the request fails at request time since the perrson attribute is stored at request scope,also the jsp:usebean body will not be executed since it specifies only a type attribute.
with the second servlet code it said it fails to compile as foo.Person is abstract.
with the third servlet code it was given like this..The code works fine and prints "Evan".
My question is: Isn't the situation with the first servlet code and third servlet code the same? why has the author given that the third code works fine?where as the first servlet code fails.
Note that the jsp:usebean action does not have a scope attribute which means the default scope-page.but the person attribute is set in the request scope.
can the author or anyone else pls give me an explaination on this question.
correct me if im wrong..pls
thanks