简体   繁体   中英

How to maintain the same session id across multiple web applications in Java

如何在Jboss服务器中为多个Web应用程序维护相同的会话ID?

Take a look at this post, for similar question. Access session of another web application

What this is saying is

"Not directly. Most containers put each WAR in a separate classloader with the EAR classloader as their parent. Each app's sessions are separate. You can put something provided by the parent EAR in each session. If you need them to share something, make it a EAR function."

So, due to the each session being private, one web-app cannot see the other. So, your option is to bundle the two web apps in a single WAR file, to make them be able to share session data.

I was looking for this recently and found a solution.

If you just want to share the ID, you can use the following configuration in web.xml. Given that you use servlet 3.0.

<session-config>
  <cookie-config>
    <path>/</path>
  </cookie-config>      
</session-config>

This will save the jsessionid cookie with path "/" making it shared among all webapps. This is how JBoss 4 used to do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM