This example will explain that how we get the property from the beans components with getter method using. It will display the value on output destination. To implify this program we just got the java file and will fetch the property from java class file.
This java file only contain the getter method that is been used to access the output. We also made two form first one is for designing and will take the reference of 2nd form and second will does the rest of work to execute the condition it self.
<html>
<head>
<title>getProperty</title>
</head>
<body bg color=“#D4E0DF”>
<formaction=“JavaExampleJSP_getProperty.jsp” method=“get”>
<tablecellpadding=“2px” cellspacing=“1px” bgcolor=“#f7f9fb” width=“400px“align=“center”>
<tr>
<tdalign=“center” colspan=“2“>
<spanclass=“text”><h2>Employye’s Info</h2></span></td>
</tr>
<tr>
<tdalign=“center” width=“60%”>Enter Employee Name: <inputtype=“text” name=“nm” maxlength=“40“/></td>
</tr>
<tr>
<tdalign=“center” width=“60%”>Enter Employee’s Job: <inputtype=“text” name=“jb” maxlength=“40“/></td>
</tr>
<tr>
<tdalign=“center” width=“60%”>Enter Employee’s Company: <inputtype=“text” name=“cm” maxlength=“40“/></td>
</tr>
<tr>
<td><center><inputtype=“submit” value=“submit” /></center></td>
</tr>
</table>
</form>
</body>
</html>
getProperty.jsp
<html>
<head>
<title><getProperty>Example In JSP</title>
</head>
<body bg color="#D4E0DF">
<%
String empName = request.getParameter("nm");
String job = request.getParameter("jb");
String company = request.getParameter("cm");
If(empName != null)
{
%>
<jsp:useBean id="wrkr" class="p2.emp" scope="request"/>
<jsp:setProperty property="empName" value="<%=empName %>" name="wrkr"/>
<jsp:setProperty property="job" value="<%=job %>" name="wrkr"/>
<jsp:setProperty property="company" value="<%=company %>" name="wrkr"/>
<h3 align="center">Employee Details are :</h3>
<table cellpadding="2px" bgcolor="#f7f9fb" width="400px"align="center">
<tr>
<td align="center">Employee Name: </td>
<td align="center"><jsp:getProperty property="empName" name="wrkr"/></td>
</tr>
<tr>
<td align="center">Employee Job: </td>
<td align="center"><jsp:getProperty property="job" name="wrkr"/></td>
</tr>
<tr>
<td align="center">Employee's Company: </td>
<td align="center"><jsp:getProperty property="company" name="wrkr"/></td>
</tr>
</table>
<%
}
%>
</body>
</html>
Emp.java
package p2;
public class emp
{
String empName;
String job;
String company;
public String getEmpName()
{
return empName;
}
public void setEmpName(String empName)
{
this.empName = empName;
}
public String getJob()
{
return job;
}
public void setJob(String job)
{
this.job = job;
}
public String getCompany()
{
return company;
}
public void setCompany(String company)
{
this.company = company;
}
}