I need to give my user a web interface to change the session timeout interval. So, different installations of the web application would be able to have different timeouts for their sessions, but their web.xml cannot be different.
Is there a way to set the session timeout programatically, so that I could use, say, ServletContextListener.contextInitialized() to read the configured interval and set it upon application startup?
Instead of using a ServletContextListener, use a
HttpSessionListener.In the
sessionCreated()method, you can set the session timeout programmatically:And don’t forget to define the listener in the deployment descriptor:
(or since Servlet version 3.0 you can use
@WebListenerannotation instead).Still, I would recommend creating different web.xml files for each application and defining the session timeout there: