Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read session-timout from web.xml

Tags:

servlets

How can i read the session-timeout from the web.xml file?

Tried

getServletContext().getAttribute("session-timeout").toString(); 

but gives me NullPointerException.

Also tried

getServletConfig().getInitParameter("session-timeout");

But gives me null because obviously this is not an init-param

like image 379
MaVRoSCy Avatar asked Jul 08 '13 13:07

MaVRoSCy


2 Answers

Here's an oneliner.

int sessionTimeoutFromWebXml = Integer.parseInt(XPathFactory.newInstance().newXPath().compile("web-app/session-config/session-timeout").evaluate(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(getServletContext().getResourceAsStream("/WEB-INF/web.xml"))));

;)

like image 165
BalusC Avatar answered Oct 03 '22 18:10

BalusC


It should be

   session.getMaxInactiveInterval();

It will return time in seconds.

like image 36
Prasad Kharkar Avatar answered Oct 03 '22 18:10

Prasad Kharkar