JSP getProperty action tag

In this post, you will learn:

  • What is the role of getProperty action in JSP?
  • How getProperty action is used in JSP?

getProperty action of JSP:

<jsp:getProperty /> action is used to write the value a bean property to the output stream. It is used when a property value is to be sent as response.

It has following syntax:

<jsp:getProperty name=”beanName” property=”propertyName” />

Let following be an external object in a JSP page.

<jsp:useBean id=”user” class=”com.techmentro.learningpad.User” scope=”session” />

To write the value of mailId property of the user bean to the output stream, following action is required.

<jsp:getProperty name=”user” property=”mailId” />

Following code will be generated in the _jspService() method of the auto generated servlet:

//MailId property value is written to the output stream
out.print(user.getMailId());

As you can see from the above example, it is a very simple action to use. It also doesn’t offer much convenience i.e. most of the time the statement which is generated for this action is more compact than the action itself. Instead of the action, that statement can be directly used in the scriptlet tag by a JSP programmer.

In the next post, use of <jsp:useBean />, <jsp:setProperty /> and <jsp:getProperty /> actions is demonstrated with the help of a practical example.

Its time to recap the main concepts:

  1. getPropety action is used to write the value of a bean property to the output stream.
  2. Unlike setProperty action, it doesn’t support * in the property name i.e. it can only write the value of a single property to the output stream.
If you like the post, then share it...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *