sharing session attribute between two subdomains i

2019-08-15 14:34发布

I am using tomcat 7.0 and java 6. I want to share session between domains and subdomain for examples.com and abc.examples.com

so in context.xml put tag

<Context antiResourceLocking="false" privileged="true" sessionCookieDomain=".examples.com" sessionCookiePath="/" >

successfully share Cookies JSESSIONID but when i set attribute in examples.com

    logger.info( "Demo1 : "+httpSession.getId());
    httpSession.setAttribute("data", "subhash lamba");
    logger.info(" Demo1 data"+ httpSession.getAttribute("data") ); 

that can not be accessible in test.examples.com subdomain

    HttpSession httpSession=request.getSession();
    logger.info( "Demo3 : "+httpSession.getId());
    logger.info(" Demo3 data "+ httpSession.getAttribute("data") );

when i log JSESSIONID in both domain and subdomain are same but when i try to share attribute between them it is not working.

1条回答
仙女界的扛把子
2楼-- · 2019-08-15 15:08

I find solution my self. I successfully get sharing session between two domain and now just my problem was identify same user. When i try for sharing session data between those two domain and sub-domains at that time it's not work because server maintain session for individual application.

Now my solution is:

In Tomcat server there is context, In context we can store Object and same Context can be accessible by every application in same Tomcat. So Now I create on java.util.Map object in java.util.Map object store key-value pair in which key is JSESSIONID and value is user Id who login. So now i can access easily user who login in domain and all sub-domains.

查看更多
登录 后发表回答