Person is a JavaBean, so we’ll use the bean-related standard actions

With a couple of standard actions, we can eliminate all the scripting code in our JSP (remember: scripting code includes declarations, scriptlets, and expressions) and still print out the value of the person attribute’s name property. Don’t forget that name is not an attribute— only the person object is an attribute. The name property is simply the thing returned from a Person’s getName() method.

Without standard actions (using scripting)

<html><body>

<% foo.Person p = (foo.Person) request.getAttribute("person"); %>
Person is: <%= p.getName() %>

</body></html>

Note

The way we’ve been doing it.

With standard actions (no scripting)

<html><body>

<jsp:useBean id="person" class="foo.Person" scope="request" />

Person created by servlet: <jsp:getProperty name="person" property="name" />

</body></html>

Note

NO Java code here! No scripting, just two standard action tags.

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.