Getting a Property value in jsp

To reduce the the scriplet code with jsp, there is an easier way of accessing properties of bean by using getProperty tag which automatically sends the result of the method.

Getting a Property value in jsp

Getting a Property value in jsp

     

This section illustrates you how to use <jsp:getProperty> tag.

To reduce the the scriplet code with jsp, there is an easier way of accessing properties of bean by using getProperty tag which automatically sends the result of the method. The tag <jsp:getProperty> has two attributes, name and property. Name attribute refers to the id of the bean and property attribute refers to the method of the bean. Here we are providing you an example which illustrates you the use of <jsp:getProperty> tag.

Here is the code of getProperty.jsp

<HTML>
<HEAD>
<TITLE>Getting a Property Value</TITLE>
</HEAD>
<BODY>
<H1>Getting a Property Value</H1>
<jsp:useBean id="bean" class="form.GetProperties" />
The text is: <jsp:getProperty name="bean" property="text" /> 
</BODY>
</HTML>

Here is the bean GetProperties.java

package form;
public class GetProperties
{
private String text="Hello World";
public String getText()
{
return text;
}
public GetProperties()
{}
}

In the above example, we are using bean with <jsp:useBean> tag. <jsp:getProperty> tag calls the bean  and its method 'text' with its attributes id and property.

Here is the output

Download Source code