permaculture playing cards
The moose likes Servlets and the fly likes Getter/Setter methods in Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getter/Setter methods in Servlets" Watch "Getter/Setter methods in Servlets" New topic

Getter/Setter methods in Servlets

Rajnarayan Deenadayalan

Joined: Dec 16, 2003
Posts: 14

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();
forward(request, response);

getting Valuein another JSP:

employee emps=new employee();

<%emps.setEmpid(100); %>

the value returns null value
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63867

Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

[Asking smart questions] [About Bear] [Books by Bear]
yang xiao

Joined: Sep 21, 2009
Posts: 2

request.setAttribute("a", a);



Expression Language:very strong Tool for passed the value from different Scope at JSP english is so so.....
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

getting Valuein another JSP:

employee emps=new employee();

<%emps.setEmpid(100); %>

the value returns null value

yes its obvious. you have set the value in Servlet and did not store/ pass ( in any means) to JSP , but still trying to access in JSP ?

Check out JSP attributes & scopes to find out which scope suits your need.
I agree. Here's the link:
subject: Getter/Setter methods in Servlets
It's not a secret anymore!