JSESSIONID Cookie with Expiration Date in Tomcat

旧城冷巷雨未停 提交于 2019-11-28 05:51:00
Sander

As of Servlet 3.0, this can simply be specified in the web.xml:

<session-config>
    <session-timeout>720</session-timeout> <!-- 720 minutes = 12 hours -->
    <cookie-config>
        <max-age>43200</max-age> <!-- 43200 seconds = 12 hours -->
    </cookie-config>
</session-config>

Note that session-timeout is measured in minutes but max-age is measured in seconds.

JB Nizet

I don't think it's possible to do what you want, without changing the Tomcat code.

Note however that it might have a nasty side effect : if a user starts a session and stays active for twelve hours, its session timeout will be updated accordingly (the timeout will be updated at each request), but its cookie won't, and the user will thus lose its session after 12 hours, even if he's been active all this time.

If you want sessions to expire after 12 hours and survive server restarts, add this to your web.xml:

<session-config>
  <session-timeout>720</session-timeout>
</session-config>

Tomcat is configured by default to serialise sessions so that they survive app restarts. See http://tomcat.apache.org/tomcat-5.5-doc/config/manager.html#Restart%20Persistence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!