Hi Everyone,
Please go through the following code from HF Book Page 356,
BE the Container
We have an abstract class called Person,
whose methods are
String getName()
and void setname(String)
We have an Employee class which extends Person class
and has methods int getEmpID() and void setEmpID(int)
and both the classes are in package foo.
and
jsp code is as follows:
<jsp:useBean id ="person" type ="foo.Employee">
<jsp:setProperty name ="person" property ="name" value ="Fred" />
</jsp:useBean>
Names is: <jsp:getProperty name ="person" property ="name" />
In the
Servlet If we have the code
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);
Figure out what the JSP code above would do for each of the three different Servlet code Examples.
The answers given are
1.
fails at request time
2.
fails to compile
3.
works fine and prints Evan.
My doubt is in 1. "person" is being added to the request and in 3."person" is added to the request
and in jsp we did not specify the scope so it will take default scope that is of page.
so why 1. is not working and 3. is working
and another doubt is
what is the difference between request in request.setAttribute and and request in
<jsp:useBean id ="person" type ="foo.Employee" scope ="request">
Are they both same?
Can any one explain in detail
Thanks in advance.