Deconstructing <jsp:useBean> and <jsp:getProperty>

All we really wanted was the functionality of <jsp:getProperty> because we wanted only to display the value of the person’s “name” property. But how does the Container know what “person” means? If we had only the <jsp:getProperty> tag in the JSP, it’s almost like using an undeclared variable—the name “person”. The Container usually has no idea what you’re talking about, unless you FIRST put a <jsp:useBean> into the page. The <jsp:useBean> is a way of declaring and initializing the actual bean object you’re using in <jsp:getProperty>.

Declare and initialize a bean attribute with <jsp:useBean>

image with no caption

Get a bean attribute’s property value with <jsp:getProperty>

image with no caption

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.