• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Session varibles not Initialized .

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
What's wrong? Where are you going? Stop! Read this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic