SetProperty Tag in JSP

In this Tutorial we want to describe you a code that help in describing an example from JSP bean set property. 

SetProperty tag in JSP is used to set properties of the JAVA bean.

General syntex of JSP setProperty Tag look like this:

<jsp:setProperty name="xyz" property="xyz" value="xyz"/>

The code include a package bean , we have a class Employees. The employee class include a string variable first name, last name and address. Inside the class we have a setter and getter method.
1. set XXX ( ): This method hold the value of the parameter by the implementor of interface.
2. get XXX( ): This method retrieve the value of the parameter set in the setXXX () method.
The JSP page uses this getter and setter method.

<jsp:useBean> –
1. The < jsp:use Bean> instantiate a bean class and locate a bean class with specific scope and name.

  • id – A id variable is used to identify the bean in the scope .
  • class -The class is represented as Package. class and instantiate a bean from class. The class should be public
  • scope -This describe you the scope of the bean in which it exists.

2. <jsp:set Property> This is used to set the value of one or more properties of bean using setter method. The value of the name must match with the Id.
3. <jsp:get Property> This is used to return the bean property value using property getter method in bean package.


package com.dineshonjava.bean;

 * @author Dinesh Rajput
public class Employee {
 private String firstName;
 private String lastName;
 private String address;
 public String getFirstName() {
  return firstName;
 public void setFirstName(String firstName) {
  this.firstName = firstName;
 public String getLastName() {
  return lastName;
 public void setLastName(String lastName) {
  this.lastName = lastName;
 public String getAddress() {
  return address;
 public void setAddress(String address) {
  this.address = address;


<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
  <h1>Employee Form Bean Value</h1>
    <jsp:useBean id="emp" class="com.dineshonjava.bean.Employee" scope="page" />
    <jsp:setProperty name="emp" property="firstName" value="Dinesh"/>
    <jsp:setProperty name="emp" property="lastName" value="Rajput"/>
    <jsp:setProperty name="emp" property="address" value="Noida"/>
       <td>First Name</td>
       <td> : </td>
       <td> <jsp:getProperty name="emp" property="firstName"/> </td>
       <td>Last Name</td>
       <td> : </td>
       <td> <jsp:getProperty name="emp" property="lastName"/> </td>
       <td> : </td>
       <td> <jsp:getProperty name="emp" property="address"/> </td>

Copy myapp folder on webapp directory of tomcat at
C:Program Files (x86)Apache Software FoundationTomcat 7.0webapps

and restart server and hit the following URL

Download Example

<<Previous <<   || Index ||   >>Next >>