我需要将 session 超时设置为 40 秒。我知道我们通常保持 20 分钟。
但是我当前的应用程序要求是将 session 超时保持在 40 秒。 web.xml 仅将整数值设为 1,但并未将其设为 0.6。有没有办法写这个?我们在 Apache tomcat 服务器上运行我们的 java web 应用程序。
那么如何在 web.xml 中以秒为单位设置 session 超时?

最佳答案

使用 deployment descriptor ,您只能以分钟为单位设置超时 :

<session-config>
    <session-timeout>1</session-timeout>
</session-config>

但是使用 HttpSession API,您可以为 servlet 容器设置 session 超时 :
HttpSession session = request.getSession();
session.setMaxInactiveInterval(40);

推荐阅读:Deployment Descriptor Elements

关于java - 如何在web.xml中以秒为单位设置 session 超时?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23005600/

10-11 23:10
查看更多