aspose file tools*
The moose likes Servlets and the fly likes Session varibles not  Initialized . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session varibles not  Initialized ." Watch "Session varibles not  Initialized ." New topic
Author

Session varibles not Initialized .

Jesu Mani
Ranch Hand

Joined: Oct 16, 2006
Posts: 34
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jesu Mani
Ranch Hand

Joined: Oct 16, 2006
Posts: 34
Now i got the session values printed.

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

to

HttpSession session = req.getSession(true);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session varibles not Initialized .