Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Determine Java Session Timeout

Tags:

java

jsp

servlets

Is there any way for a java servlet/jsp to determine the webserver's session timeout (in seconds, minutes, etc...)? I tried looking in the HttpSession and System API, but didn't see any property for determining the webserver's session timeout. I know that this value is set in web.xml, but I am designing a java library which needs to determine this through code.

Note: I am designing for a generic webserver and cannot rely on vendor specific extensions.

like image 388
David Avatar asked Dec 16 '09 14:12

David


1 Answers

The session's timeout is determined by idle time so there is no way to know when it will timeout.

However, you can calculate the next possible timeout assuming session is not being accessed,

Date expiry = new Date(session.getLastAccessedTime() + session.getMaxInactiveInterval()*1000);

 

like image 147
ZZ Coder Avatar answered Nov 05 '22 06:11

ZZ Coder