如何在 web.xml 中以秒为单位设置会话超时? [英] How do I set session timeout in seconds in web.xml?

查看:29
本文介绍了如何在 web.xml 中以秒为单位设置会话超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将会话超时设置为 40 秒.我知道我们通常保持在 20 分钟.

I have a requirement to set the session timeout of 40 seconds. I know we keep normally to 20 minutes.

但我目前的应用要求是将会话超时保持在 40 秒.web.xml 仅将整数值设为 1,但并未将其设为 0.6.有没有办法写这个?我们正在 Apache tomcat 服务器上运行我们的 Java Web 应用程序.

But my current application requirement is to keep the session timeout to 40 seconds. The web.xml is taking only integer value as 1 but it is not taking 0.6. Is there any way to write this? We are running our java web application on Apache tomcat server.

那么如何在 web.xml 中以秒为单位设置会话超时?

So how do I set session timeout in seconds in web.xml?

推荐答案

使用 部署描述符,你只能设置超时分钟:

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


但是使用 HttpSession API 您可以为 servlet 容器设置会话超时以秒为单位:


But using the HttpSession API you can set the session timeout in seconds for a servlet container:

HttpSession session = request.getSession();
session.setMaxInactiveInterval(40);

<小时>

建议阅读:部署描述符元素

这篇关于如何在 web.xml 中以秒为单位设置会话超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆