Share session data between 2 subdomains

前端 未结 3 960
忘了有多久
忘了有多久 2020-12-15 14:00

I am using tomcat 7.0.6 with jdk 1.6.0_22

Is it possible to share session data between 2 different domains with a common subdomain such as a.mydomain.com and b.mydom

3条回答
  •  -上瘾入骨i
    2020-12-15 14:25

    Set the sessionCookieDomain attribute of 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.

    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 element of the webapps in question to /.

    In a nutshell:

    
    

    See also:

    • Tomcat 7 configuration reference - The Context container

    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 element in /conf/server.xml for the case that you've multiple webapp contexts for which you'd like to share the session.

提交回复
热议问题