jsp: setProperty tag

jsp: setProperty tag

The jsp: setProperty tag is used to set the value or save the value of the instance of the JavaBeans. The following is the syntax of the jsp: setProperty tag:


< jsp: setProperty name = “name of bean” property = “name of property” >

In the syntax we have the name attribute and the property attribute. We can also add other attributes for example the param attribute to include parameters and the value attribute to add the value of the property. The name attribute is used to specify the name of the instance of JavaBean. The name attribute of the setProperty tag and the id attribute of useBean tag. The property attribute is used to specify the property of the JavaBean.


Example of setProperty with JavaBean:

Consider the following example in which we have a java class and a JSP page and we used the jsp: setProperty tag to change or store the value of the property:

EmployeeBean. java:

import java.io.Serializable;

public class EmployeeBean implements Serializable


 private String n;

  public EmployeeBean()


    this. n = “”;


   public void settingName (String n)


    this. n = n;


   public String gettingName ()


    return n;




< html >

< head >

< title >JSP Page < /title >

</ head >

<jsp: useBean id = “employee” class = “EmployeeBean” scope = “request” / >

<jsp: setProperty name = “employee” property = “name” value = “Stuart” / >

< body >

Name of the employee: < jsp: getProperty name = “employee” property = “name” />

</ body >

</ html >

In the above example the jsp: useBean tag is used to declare a bean named as “employee” in the JSP page. And the value of the property will be printed. We have also set the value of property by using the jsp: setProperty tag.

The above code will generate the following output:


Name of the employee: Stuart

In this way we can make a very complex Java bean and these java beans can have a number of properties. The tags jsp: useBean, jsp: getProperty and setProperty can be used to get and set the values of the properties and through these tags we can create a complex Java Bean.