JSP Standard Actions 'jsp:setProperty' & 'jsp:getProperty'

In this section , we will discuss about Standard actions - 'jsp:setProperty' & 'jsp:getProperty' with an example.


Share on Google+Share on Google+

JSP Standard Actions 'jsp:setProperty' & 'jsp:getProperty'


In this section , we will discuss about Standard actions - 'jsp:setProperty' & 'jsp:getProperty' with an example.

JSP Standard Actions <jsp:setProperty> & <jsp:getProperty>


It sets a property value or values in a Bean only if a new object was instantiated, not if an existing one was found.


            property= "*"   |
            property="propertyName" [ param="parameterName" ]   |
            property="propertyName" value="{string | <%= expression %>}"

Example :

<jsp:setProperty name="Ibean" property="*" />

<jsp:setProperty name="Ibean" property="user" />

<jsp:setProperty name="Ibean" property="user" value="Ankit" />

Attributes :

  • name="beanInstanceName"  :

The name of an instance of a Bean that has already been created or located with a <jsp:useBean> element. The value of name must match the value of id in <jsp:useBean>. The <jsp:useBean> element must appear before <jsp:seProperty> in the JSP file.

  • property="*"

The value of "*" means that all request parameters whose names match bean property names will be passed to the appropriate setter methods.

  • property="propertyName" [ param="parameterName" ]

Sets one Bean property to the value of one request parameter. In the syntax, property specifies the name of the Bean property and param specifies the name of the request parameter by which data is being sent from the client to the server.

If the Bean property and the request parameter have different names, you must specify both property and param. If they have the same name, you can specify property and omit param. If a parameter has an empty or null value, the corresponding Bean property is not set.

  • value="{string | <%= expression %>}

This optional attribute specifies the value for the property. String values are automatically converted to numbers, boolean, Boolean, byte, Byte, char, and Character via the standard valueOf method in the target or wrapper class. For example, a value of "true" for a boolean or Boolean property will be converted via Boolean.valueOf, and a value of "42" for an int or Integer property will be converted via Integer.valueOf.


This element retrieves the value of a bean property, converts it to a string, and inserts it into the output. The two required attributes are:

  •  name: the name of a bean previously referenced via <jsp:useBean>.
  •  property: the property whose value should be fetched.

Syntax :

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

Limitations of <jsp:getProperty>:

  • You cannot use <jsp:getProperty> to retrieve the values of an indexed property.
  • You can use <jsp:getProperty> with JavaBeans components, but not with enterprise beans. As alternatives, you can write a JSP page that retrieves values from a Bean that in turn retrieves values from an enterprise bean, or you can write a custom tag that retrieves values from an enterprise bean directly.
Example : Given below a example that loads a bean and sets/gets a simple String parameter :



<TITLE>JavaBeans in JSP</TITLE>

<meta http-equiv="Content-Language" content="en-us">

<style type="text/css">

.style1 {

border: 2px solid #0000FF;

background-color: #CCFFFF;





<table class="style1" style="float: CENTER" align="center">


<td style="width: 430px; height: 38px">






<jsp:useBean id="test" class="foo.usebeanexample" />

<jsp:setProperty name="test" property="message" value="Hello ANKIT" />


<jsp:getProperty name="test" property="message" />




Given below is the code for the bean used in the "usebean.jsp" :


package foo;

public class usebeanexample {

private String message = "No message specified";

public String getMessage() {


public void setMessage(String message) {

this.message = message;}


Output of  "usebean.jsp"

Download Source code

See Also :(click below)

JSP Standard Action <jsp:useBean>


Posted on: June 17, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles