File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null object when calling session context object

 
Srikanth Devaraju
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SessionContext has been deprecated, not the Session.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://java.sun.com/products/servlet/2.2/javadoc/index.html
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic