• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session varibles not Initialized .

 
Jesu Mani
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I am trying with some simple servlet programs . I am printing the session object within the doget()method. And also tried to print the session object within the if {} block. Here this session value prints null.Is that the reason that the session is not initialized. i have placed this snippet in doget().

I expect someone to put a light on this ?

// Save and get a session-scoped value
HttpSession session = req.getSession(false);
if (session != null) {
session.setAttribute("session-param", "session-value");
value = session.getAttribute("session-param");
}
Thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no code that prints the session variable so we can't tell you why it is or isn't working on your machine.

In order for us to help you, you'll need to post post some real code.
When you do, please use UBB code tags. and avoid red herrings.. There is no doget method in the servlet spec. It's doGet. Case matters in Java.

A good code example will help us to figure out exactly what's going on with your program and will allow us to give you better help.
 
Jesu Mani
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now i got the session values printed.

I changed this :
HttpSession session = req.getSession(false);

to

HttpSession session = req.getSession(true);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic