在2个子域之间共享会话数据 [英] Share session data between 2 subdomains
问题描述
我正在使用tomcat 7.0.6和jdk 1.6.0_22
I am using tomcat 7.0.6 with jdk 1.6.0_22
是否可以在两个不同的域之间共享具有公共子域的会话数据,例如a.mydomain .com和b.mydomain.com?
Is it possible to share session data between 2 different domains with a common subdomain such as a.mydomain.com and b.mydomain.com ?
使用默认的java servlet a.mydomain.com和b.mydomain.com获取不同的会话,但是不可能在mydomain.com中为所有子域创建一个共享会话?
With the default java servlet a.mydomain.com and b.mydomain.com get different sessions, but is it not possible to create a shared session for all subdomains in mydomain.com?
问题还在于我没有直接控制commen子域(mydomain.com)所以我可以'吨服务于任何的servlet从mydomain.com
The problem is also that I don't directly control the commen subdomain (mydomain.com) so I can't serve any servlets from mydomain.com
推荐答案
将 sessionCookieDomain
属性< Context>
有问题的webapp元素 .mydomain.com
(注意前导点,这是很重要)。这将允许webbrowser在所有子域之间共享cookie。
Set the sessionCookieDomain
attribute of <Context>
element of the webapp in question to .mydomain.com
(note the leading dot, this is very important). This will allow the webbrowser to share cookies among all subdomains.
如果您实际上有多个webapp上下文并且您想要在它们之间共享会话,那么您还需要设置 sessionCookiePath
的属性<语境GT;
所讨论的Web应用程序的元素以 /
。
If you actually have multiple webapp contexts and you want to share the session between them as well, then you also need to set sessionCookiePath
attribute of <Context>
element of the webapps in question to /
.
简而言之:
<Context sessionCookieDomain=".mydomain.com" sessionCookiePath="/">
参见:
- Tomcat 7配置参考 - 上下文容器
- Tomcat 7 configuration reference - The Context container
See also:
对于Tomcat 6用户:请注意,这是在Tomcat 6.0.27中引入的。对于那些无法升级的人,您需要一个 Valve
来修改cookie域,最终与 emptySessionPath
结合使用对于您有多个webapp上下文的情况,< Connector>
元素在 /conf/server.xml
中的属性您想要分享会话。
For Tomcat 6 users: note that this was introduced in Tomcat 6.0.27. For those who can't upgrade, you would need a Valve
to modify the cookie domain, eventually in combination with emptySessionPath
attribute in <Connector>
element in /conf/server.xml
for the case that you've multiple webapp contexts for which you'd like to share the session.
这篇关于在2个子域之间共享会话数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!