sharing session attribute between two subdomains in tomcat

删除回忆录丶 提交于 2020-01-05 12:23:27

问题


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:


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.



来源:https://stackoverflow.com/questions/20296438/sharing-session-attribute-between-two-subdomains-in-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!