The code illustrate an example from JSP bean get property. In this example we define a package bean include a class Employees. Inside the class we declared a String variable first Name, last Name and address. The get Address, first Name, last Name return you the value from a bean in JSP page. The JSP page uses bean get property and return the value stored in it.
<jsp:useBean> -
Attributes used in <jsp:useBean>
<jsp:get Property> -
The <jsp:useBean>element contains a <jsp:getProperty> element that is used to retrieve the value stored in the getter method.
In order to run this program we need to place the file inside the Tomcat Home\WebApps\jsp bean get Property and start your tomcat. Once Tomcat is started ,type the url browser and run your application.
jsp bean getproperty.jsp
<html>
<body>
<h1>Get Value from bean</h1>
<jsp:useBean id="emp" class="bean.Employees"/>
<table>
<tr>
<td>First Name :
<jsp:getProperty name="emp" property="firstName"/>
</td>
</tr>
<tr>
<td>Last Name :
<jsp:getProperty name="emp" property="lastName"/>
</td>
</tr>
<tr>
<td>Address :
<jsp:getProperty name="emp" property="address"/>
</td>
</tr>
</table>
</body>
</html>
|
package bean; public class Employees {
protected String firstName;
protected String lastName;
protected String address;
public String getAddress() {
address = "Delhi";
return address;
}
public String getLastName() {
lastName = "Singh";
return lastName;
}
public String getFirstName() {
firstName = "Komal";
return firstName;
}
}
|
Output of the program

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: JSP bean get property View All Comments
Post your Comment