Tomcat的创建一个新的会话为每个请求 [英] Tomcat create a new session for every request

查看:197
本文介绍了Tomcat的创建一个新的会话为每个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在这个问题上2天,现在,我希望任何人在这里也有类似的问题,并为解决方案。

I am working on this problem for 2 days now and I am hoping that anyone here had a similar problem and a solution for that.

问题: 这是一个Spring MVC的(2.5.6)的Web应用程序,它运行在Tomcat中6。 当请求的开始页面重定向用户到JSP页面(通过使用HTML的元刷新标记),它加载它的内容有很多Ajax请求(框架:原型)的。问题是,Tomcat的创建为每个AJAX请求(约67次)一个新的会话。 我首先想到的是,会话Cookie存储加载起始页后的Ajax请求强制Tomcat来创建一个新的会话。我的方法是手动创建的会话cookie,但这并没有什么差别。 有趣的是,它在其他一些Tomcat实例,而不是在为集成测试所需的环境。在我看来这是一个Tomcat的配置问题。

The problem: It's a Spring MVC (2.5.6.) Web Application, which runs in Tomcat 6. When the start page is requested it redirects the customer to a JSP Page (by using HTML's meta refresh tags) which loads it's content with a lot of Ajax requests (Framework: Prototype). The problem is that Tomcat creates a new session for every AJAX requests (about 67 sessions). My first thought was that the Session Cookie is stored after the start page is loaded and the Ajax requests forces the Tomcat to create a new session. My approach was to create the session cookie by hand, but this did not make any difference. The funny thing is that it works in some other tomcat instances, but not in the desired environment for the integration tests. In my opinion it's a Tomcat configuration issue.

在进一步调查与萤火虫,我发现的Tomcat会为每个请求,即使正确JSESSIONID被转移到一个新的会话(50B5EA0BCFE811C744CE9C1F9EDE0097):

After further investigation with Firebug, I found out that Tomcat creates a new Session for every request even if the right JSESSIONID is transfered to it (50B5EA0BCFE811C744CE9C1F9EDE0097):

Request Header 1: 
Cookie JSESSIONID=F3206CBF2C961E125821FF22FA31A02D

Response Header 1:
Set-Cookie JSESSIONID=49E000B4D6880F4F94531AB9C78DB667; Path=/JOCA-Music-Portal   JSESSIONID=50B5EA0BCFE811C744CE9C1F9EDE0097; Path=/JOCA-Music-Portal

Request Header 2:
Cookie JSESSIONID=50B5EA0BCFE811C744CE9C1F9EDE0097

Response Header 2:
Set-Cookie JSESSIONID=DCCA2D1B98D11223A6B8855800276E27; Path=/JOCA-Music-Portal

更新:进一步调查中分离的问题Tomcat的领域配置。我们使用JDBC领域进行登录。当登录时deativated,只有一个会话被创建。 如果它被激活,Tomcat的创建无效/过期的会议,这就是为什么新的会话与每个请求创建。但为什么Tomcat的表现也是这样吗?

UPDATE: Further investigation isolated the problem to the Tomcat Realm configuration. We use a JDBC Realm for login. When the login is deativated, only one Session is created. If it's activated, Tomcat creates invalidated/expired sessions, that's why a new session is created with each request. But why does Tomcat behave like this?

我真的很绝望,所以任何想法/提示/解决方案非常AP preciated。

I'm really desperate, so any thought/hint/solution is well appreciated.

非常感谢你。

推荐答案

您可以尝试分析HTTP流量您的客户端和服务器之间。确保Cookie头设置正确的请求和响应。

You can try to analyze the HTTP traffic between your client and your server. Make sure the Cookie header is set correctly in the request and the response.

如果使用的是Firefox,你可以尝试用调试萤火虫

If using Firefox, you can try to debug with Firebug.

这篇关于Tomcat的创建一个新的会话为每个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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