Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Null object when calling session context object

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Everybody,
I am learning sessions in servlet. I am using "Resin" webserver.
To understand the session context object I am executing folloing code.
==== Code====
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
// Get the current session object, create one if necessary
HttpSession dummySession = req.getSession(true);
// Use the session to get the session context
HttpSessionContext context=dummySession.getSessionContext();
Enumeration ids = context.getIds();
==== Code ends===
I am getting null pointer exception on the last statement(i.e. Enumeration ids = context.getIds() . So I came to know that getSessionContext function is not returing a session context object. What I am doing wrong? I will appreciate anybody's help in this regard.
Thanks,
Srikanth.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the documentation. The getSessionContext method has been deprecated as a security risk. The method is still there but it returns null.
Bill
------------------
author of:
 
Srikanth Devaraju
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thank you so very much. I have one follow-up question.
So sessions management can be done only by cookies and hidden fields? Is there any alternate for session context object? I read some where that whole session concept is depricated from the servlet. Is that true.
Once again thank you very much.
Regards,
Srikanth.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The SessionContext has been deprecated, not the Session.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cookies, Hidden Fields and URL Rewriting are the only ways I know of to associate a particular user with a session.
HttpSession is still very much a part of the API - it is essential to just about everything.
You really should download the servlet and JSP API documents from java.sun.com -
Bill
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://java.sun.com/products/servlet/2.2/javadoc/index.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic