This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Session Timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Timeout" Watch "Session Timeout" New topic
Author

Session Timeout

Sri Ram
Greenhorn

Joined: Feb 13, 2006
Posts: 20
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?


Sriram<br />SCJP<br />SCWCD
Hendy Setyo Mulyo
Ranch Hand

Joined: Dec 01, 2004
Posts: 219

How did you set the session timeout in web.xml? Can give the snippet?


Hendy Setyo Mulyo
SCJP 1.4 (95%), SCWCD 1.4 (94%)
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
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.


SCJP 1.4 & 1.5, SCWCD 1.5. Learn and Let Learn.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I am sure you session is not expired.You can try setting a session listner for tracking whether session has really expired or not.


Rahul Bhattacharjee
LinkedIn - Blog
Ryan Day
Ranch Hand

Joined: Apr 03, 2006
Posts: 87
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.


SCJP, SCWCD
Soma Kora
Greenhorn

Joined: Apr 10, 2007
Posts: 6
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

Joined: Feb 06, 2007
Posts: 8
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.


With Regards<br /> Jilani Jidni<br /> Bangladesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session Timeout
 
Similar Threads
Session timoeout on JSP
problem using getSession(boolean create)
session managment
Checking to see if my session has expired
Checking to see if a session has expired