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
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"))));
;)
It should be
session.getMaxInactiveInterval();
It will return time in seconds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With