Servlet会话超时 [英] Servlet Session timeout

查看:172
本文介绍了Servlet会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写我的SPring MVC Web应用程序。

I'm writing my SPring MVC web application.

我已将会话时间设置为10080分钟,相当于1周。
现在我想让用户每次打开浏览器时都保持登录状态:

I have set my session time out to be 10080 minutes equal to 1 week. Now I would like to keep user logged in every time he open browser:

sessionService.setcurrentUser(myuser);
      HttpSession session = request.getSession();
      Cookie cookie = new Cookie("JSESSIONID", session.getId());
      cookie.setMaxAge(timeout);
      response.addCookie(cookie);

我的cookie Max Age应该与会话超时相同吗?

Should my cookie Max Age be the same as session time out?

cookie.setMaxAge(10080);

这是好的做法吗?

推荐答案

您使用Cookie来引用您的会话ID。如果cookie的超时低于会话,则它将不再找到您的会话。因此,建议将cookie的超时设置为至少超出会话的超时时间。

You use cookies to refer to your session id. If the timeout of the cookie is lower than the session, it will not find your session anymore. So setting your timeout of your cookie to at least the timeout of your session is advisable.

这篇关于Servlet会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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