aspose file tools*
The moose likes Servlets and the fly likes Null object when calling session context object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Null object when calling session context object" Watch "Null object when calling session context object" New topic
Author

Null object when calling session context object

Srikanth Devaraju
Greenhorn

Joined: Oct 27, 2000
Posts: 10

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

Joined: Mar 22, 2000
Posts: 12823
    
    5
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

Joined: Oct 27, 2000
Posts: 10

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

Joined: Feb 20, 2001
Posts: 3695

The SessionContext has been deprecated, not the Session.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
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

Joined: Jul 22, 2000
Posts: 9052
    
  12
http://java.sun.com/products/servlet/2.2/javadoc/index.html


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
 
subject: Null object when calling session context object