Home Jsp Getting a Property value in jsp
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Getting a Property value in jsp

Advertisement
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

     

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

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 5, 2008

Ask Questions?    Discuss: Getting a Property value in jsp   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com