tags:

views:

317

answers:

4

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.

+2  A: 

HttpSession.getMaxInactiveInterval provides this value

dpb
A: 

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.getMaxInactiveInternal()*1000);
ZZ Coder
A: 

You can call getMaxInactiveInterval on your session object.

stimpie
A: 

In a Servlet use:

int timeoutInSeconds = request.getSession().getMaxInactiveInterval();

In a JSP use:

<p>Timeout in seconds: ${pageContext.session.maxInactiveInterval}</p>
BalusC