How to read session-timout from web.xml

后端 未结 2 652
别那么骄傲
别那么骄傲 2021-01-13 07:21

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

Tried

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


        
相关标签:
2条回答
  • 2021-01-13 07:53

    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"))));
    

    ;)

    0 讨论(0)
  • 2021-01-13 08:03

    It should be

       session.getMaxInactiveInterval();
    

    It will return time in seconds.

    0 讨论(0)
提交回复
热议问题