JSP Tutorial Step by Step
The jsp:getProperty Action
The jsp:getProperty Action
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, and property, the property whose value should be inserted.
Here's an example
<jsp:useBean id="myName" ... />
...
<jsp:getProperty name="myName"
property="someProperty" ... />
Here is a very simple example
test.jsp
<HTML>
<HEAD>
<TITLE> JavaBeans in JSP</TITLE>
</HEAD>
<BODY>
<jsp:useBean id="test" class="com.EmpBean" />
<jsp:setProperty name="test"
property="name"
value="Das" />
Name is :
<jsp:getProperty name="test" property="name" />
</BODY>
</HTML>
Output is :
Name is : Das
<jsp:getProperty name="test"
property="name"
/>
is equivalent to
out.println(test.getName());
EmpBean.java
Here's the source code for the bean used in the test.jsp page.
package com;
public class EmpBean {
private String name = "";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
The below code
<jsp:useBean id="test" class="com.EmpBean" />
is equivalent to
com.EmpBean test = new com.EmpBean();
and
<jsp:setProperty name="test"
property="name"
value="Das" />
is equivalent to
test.setName("Das");
and
<jsp:getProperty name="test" property="name" />
is equivalent to
out.println(test.getName());
|