我将 HttpSession 与 Tomcat 6 一起使用。我在其中部署 Web 应用程序的第一个 Tomcat 6 实例具有我期望的 Tomcat session 行为(我将 session 的 maxInactiveInteval 设置为 30 分钟)。
Update: I added more code to the following to demonstrate exactly how I'm setting this timeout on a session
这是我第一次设置 session 的方式:
session = request.getSession(true);
session.setAttribute(USER_CREDENTIALS, new Credentials(username, password));
session.setMaxInactiveInterval(60*30);
然后我有一个拦截器来检查这个 session :
HttpSession session = request.getSession(true);
Credentials cred = (Credentials) session.getAttribute(AuthController.USER_CREDENTIALS);
在我开发的 Tomcat 实例中似乎工作正常,但在 Tomcat 6 的另一个实例中,在负载平衡环境中,maxInactiveInteval 似乎没有得到遵守。
Update: What I mean is that the users session expires if the user is inactive (no new requests) for approximately ten seconds.
代码中没有其他地方设置了 maxInactiveInteval。是什么导致了这种行为?
最佳答案
根据对该问题的评论,您的具体问题是负载平衡的 Tomcat 实例几乎立即使 session 过期。设置/更改 <session-timeout>
和 setMaxInactiveInterval()
只是根本没有帮助。
您首先需要通过使用 Firebug 跟踪 cookie 流量来排除客户端的嫌疑。和/或 Fiddler .如果 cookie 流量看起来正常(即客户端在所有后续请求中返回正确的 session cookie),则负载均衡器或 Tomcat 配置已损坏。这不是编程错误,而是服务器管理员的食物。
关于java - Tomcat 6 : Max Session Idle time different between instances,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7895444/