Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Timeout

 
Sri Ram
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a session time out configured in the web.xml.In my filter I use request.getSession(false).Then I check the value in my session object.But even after the session has expired my session object does not get a null value.



Can you tell me how to check if my session has expired?
 
Hendy Setyo Mulyo
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you set the session timeout in web.xml? Can give the snippet?
 
Jetendra Ivaturi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
session.getSession(false) will return pre-existing session. It returns null only when there is no session associated with.

we have some methods like

getCreationTime()
getLastAccessedTime()
invalidate();

by using getLastAccessedTime() we get some time in milliseconds

and if it exceeds the time you have mentioned(<session-timeout> in web.xml(that represents hours) call invalidate() so that the session will be destroyed.


hope this works.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure you session is not expired.You can try setting a session listner for tracking whether session has really expired or not.
 
Ryan Day
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jetendra Ivaturi:
(<session-timeout> in web.xml(that represents hours)


The
<session-config>
<session-timeout>?</session-timeout>
</session-config>

Is actually minutes.
 
Soma Kora
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Here I am facing one problem. I am checking session validity

1: if (! request.isRequestedSessionIdValid())
return mapping.findForward("invalidSession");

2: user = (User)request.getSession().getAttribute("user");
if (user == null){
// throw exception if it is null;
throw new ApplicationException("User session unavailable");
}

Problem: In line i get true for request.isRequestedSessionIdValid() but when i am trying to get value from session(ie line 2) it is giving "User session unavailable")?

Can you pls suggest where went wrong?

Thanks.
 
Jilani Jidni
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello kora,

You are checked for session availability and session is available. But you try to get session with attribute "user". Please check session with user attribute are available in your session. otherwise check whether you set your session.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic