I am working on a employee form,creating a form bean for employee (setter and getter methods)
In doPost method of a
servlet to set the values.but when trying to access getter methods in another
JSP
Iam not able to ,it is returning null value.please suggest what would be the issue
Below is the code:
Bean class:
public class employee {
int empid;
String role;
public int getEmpid() {
return empid;
}
public void setEmpid(int empid) {
this.empid = empid;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}
Setting value in Servlet:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
employee a=new employee();
a.setEmpid(100);
a.setRole("Installer");
getServletConfig().getServletContext().
getRequestDispatcher("/index.jsp").
forward(request, response);
}
getting Valuein another JSP:
index.jsp
<%
employee emps=new employee();
%>
<%emps.setEmpid(100); %>
the value returns null value