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.

Get Head First Servlets and JSP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.