• Post Reply Bookmark Topic Watch Topic
  • New Topic

HFSJ Question Pg No 356  RSS feed

Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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



works fine

if the first one fails.....why the third one is working...???

Please help.
author & internet detective
Posts: 37871
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!