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

We need more code to get the Person’s name

Sending the result of getAttribute() to print/write statement doesn’t give us what we want—it just runs the object’s toString() method. And since class Person doesn’t override its inherited Object.toString(), well, you know what happens. But we want to print the Person’s name.

JSP code

image with no caption

OR using an expression

<html><body>
Person is:
<%= ((foo.Person) request.getAttribute("person")).getName() %>
</body></html>

What we GOT:

image with no caption

But then we remember that MEMO...

The one that can be summarized as “Use Scripting and Die”

We need a different approach.

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