O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Can you make polymorphic bean references?

When you write a <jsp:useBean>, the class attribute determines the class of the new object (if one is created). It also determines the type of the reference variable used in the generated servlet.

The way it is NOW in the JSP

image with no caption

But... what if we want the reference type to be different from the actual object type? We’ll change the Person class to make it abstract, and make a concrete subclass Employee. Imagine we want the reference type to be Person, and the new object type to be Employee.

image with no caption

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required