<jsp:setProperty name="xyz" property="xyz" value="xyz"/>The code include a package bean , we have a class Employees. The employee class include a string variable first name, last name and address. Inside the class we have a setter and getter method.
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; } }
<%@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