Win a copy of Functional Reactive Programming this week in the Other Languages forum!
    Bookmark Topic Watch Topic
  • New Topic

session managment

 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
If session has expired in my application, then if i say request.getSession() will it return null or new session object.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
request.getSession() and request.getSession(true) should NEVER return null.

You'll get a new session.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Report post to moderator
hi Marc,
This is what i am trying to do.... i have configured my application to expire after 5 minutes....as a result ,





sessionDestroyed method if the above code is called... But after the call , i click on a link in my jsp, controll is transferred to servlet and in the servlet in say request.getSession(false) i am getting a new session object, although my session has timed out. I have tried the above by setting the parameter as true or false but in both cases it gives me new session object.........

I am expecting that if the session has expired request.getSession(false) should return null..
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
In that case, something else is creating a new session before the servlet code's request.getSession(false) is reached: a JSP, another servlet, or something.

Your mention of "control being transferred to the servlet" implies to me that the link does not go directly to the servlet. Is that true? If the link goes straight to the servlet there should be no problem.

Anyway, your best bet in the real world is usually to set up an Intercepting Filter. That way your session check is performed before any other code is reached. This can assure you that a new session is not accidentally created.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Report post to moderator
Marc,
i have posted a similar problem problem using getSession(boolean create) . If you have a look at it.. you will see that problem using getSession(false) is creating new session, though it should return null.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Continued
 
    Bookmark Topic Watch Topic
  • New Topic