<jsp:useBean id="myName" ... /> ... <jsp:getProperty name="myName" property="someProperty" .../>Explanation: As shown above, getProperty tag in JSP has two attributes "name" and "property". Please note that jsp:getProperty tag must be used with jsp:useBean tag.
package com.dineshonjava.bean;
/**
* @author Dinesh Rajput
*
*/
public class Employee {
private String firstName;
private String lastName;
private String address;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
index.jsp<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<body>
<h1>Employee Form Bean Value</h1>
<jsp:useBean id="emp" class="com.dineshonjava.bean.Employee" scope="page" />
<jsp:setProperty name="emp" property="firstName" value="Dinesh"/>
<jsp:setProperty name="emp" property="lastName" value="Rajput"/>
<jsp:setProperty name="emp" property="address" value="Noida"/>
<table>
<tr>
<td>First Name</td>
<td> : </td>
<td> <jsp:getProperty name="emp" property="firstName"/> </td>
</tr>
<tr>
<td>Last Name</td>
<td> : </td>
<td> <jsp:getProperty name="emp" property="lastName"/> </td>
</tr>
<tr>
<td>Address</td>
<td> : </td>
<td> <jsp:getProperty name="emp" property="address"/> </td>
</tr>
</table>
</body>
</html>

Labels: JSP