dan*_*nik 3 java servlets spring-mvc
我正在编写我的SPring MVC Web应用程序.
我将会话时间设置为10080分钟,等于1周.现在我想让用户每次打开浏览器时都会登录:
sessionService.setcurrentUser(myuser);
HttpSession session = request.getSession();
Cookie cookie = new Cookie("JSESSIONID", session.getId());
cookie.setMaxAge(timeout);
response.addCookie(cookie);
Run Code Online (Sandbox Code Playgroud)
我的cookie Max Age应该与会话超时相同吗?
cookie.setMaxAge(10080);
Run Code Online (Sandbox Code Playgroud)
这是好习惯吗?
您应该将其配置web.xml
,而不是通过黑客攻击默认会话cookie.
<session-config>
<session-timeout>10080</session-timeout>
</session-config>
Run Code Online (Sandbox Code Playgroud)
请注意,您不应在会话中存储过多数据和/或您的服务器有足够的内存.
归档时间: |
|
查看次数: |
8929 次 |
最近记录: |