Signup/Sign In

JSP jsp:getProperty Tag

The getProperty tag is used to retrieve a property from a JavaBeans instance. The syntax of the getProperty tag is as follows:

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

The name attribute represents the name of the JavaBean instance. The property attribute represents the property of the JavaBean whose value we want to get.

getProperty Tag


Example of getProperty with Java Bean

Following is our Java class.

PersonBean.java

import java.io.Serializable;

public class PersonBean implements Serializable
{
  private String name;
  
  public PersonBean()
  {
    this.name="";
  }
  public void setName(String name)
  {
    this.name = name;
  }
  public String getName()
  {
    return name;
  }
}

hello.jsp

<html>
    <head>
        <title>Welcome Page</title>
    </head>
    <jsp:useBean id="person" class="PersonBean" scope="request" />
  <body>
        Name of Person is : <jsp:getProperty name="person" property="name" />
  </body>
</html>

This will print the value of the property. What if you need to change the value of the property. Let's learn how to set value of the property in our next lesson.