I am reading HFSJ and found a question at Pg No 356 as mentioned below.
I am not able to find out the reason for the answers....please suggest
Look at this standard action
Here Person is an abstract class with get and setName methods.Employee extends Person class with get and setEmpId methods.
Now Imagine that a servlet does some work and then forwards the request to the jsp that has the code above.
Figure out what the jsp code above would do for each of the three different servlet code example.
As per HFSJ, the answer are as:
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 an existing bean attribute of that name and scope
This is not clear to me....the attribute has been set in request before forwarding it to the jsp.
Please correct me if wrong
if the first one fails.....why the third one is working...???
It's subtle. The JSP wants an exact type match. In #1, you have a person. You know it's an Employee, but Java doesn't because a person type was set in the request. In #3, the employee was set directly so Java can deduce it's type.
In practice this isn't such a problem, because it isn't great practice to set values in a JSP. For the sake of example - or certification - it's an important point though.
ps - if you are planning to run this example, you have a typo in "preson"