JSESSIONID Cookie与Tomcat中的到期日期 [英] JSESSIONID Cookie with Expiration Date in Tomcat
问题描述
为Tomcat为servlet会话发送的JSESSIONID cookie设置到期日期的最佳方法是什么?
What's the best way to set an expiration date for the JSESSIONID cookie sent by Tomcat for a servlet session?
默认情况下,cookie的过期日期似乎是会话,这意味着会话在浏览器重新启动时在客户端中消失。但我想保持它打开12小时,即使在浏览器重新启动后(然后将相应地配置服务器中的会话超时)。
By default, the expiration date of the cookie seems to be 'session', which means that the session disappears in the client as soon as the browser restarts. But I would like to keep it open for 12h, even after a browser restart (and would then configure the session timeout in the server accordingly).
有任何方法在Tomcat中设置到期日期,例如使用一些配置选项还是扩展模块?或者是否有可靠的方法使用Servlet过滤器为JSESSIONID设置过期日期?
Is there any way to set an expiration date within Tomcat, e.g. using some configuration option or extension module? Or is there a reliable way to set an expiration date for JSESSIONID using a Servlet filter?
推荐答案
我知道这是一个老问题,但是如果任何人正在寻找这个信息:
I know this is an old question, but if anyone else is looking for this information:
在Servlet 3.0中,这可以简单地在web.xml中指定:
In Servlet 3.0, this can simply be specified in the web.xml:
<session-config>
<session-timeout>525600</session-timeout>
<cookie-config>
<max-age>31536000</max-age>
</cookie-config>
</session-config>
这篇关于JSESSIONID Cookie与Tomcat中的到期日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!