• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getSession()

 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"When you call getSession() is that you get an instance of a class that implements the HttpSession interface. It is Container's job to create the implementation."


The above text is from HFSJ book, chap:6,page:241. I am not getting this concept. As I know when you call getSession(), you get a new session ID or the old one (if any). Can anyone please clear my doubt?
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Please have a look at the following API which indicates that HttpSession is returned when you call getSession().

HttpSession getSession(boolean create)
Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.


The Id is not returned directly as a result of this method call. You need to get that using HttpSession.getId()

As HttpSession is an interface the container is left with the responsibility to implement it and return you the instance of the implementation which you refer using the TYPE "HttpSession".



Hope this clears your doubt.

Regards,
amit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic