How to share value between 2 war files?

Discussions

General J2EE: How to share value between 2 war files?

  1. How to share value between 2 war files? (4 messages)

    I have 2 war files running on the same web server. There is a login jsp page in the first war. When the user login through the login page, how can I pass the userid to the second war (for example, pass the first web application userid to the session of second web application)?


    Any idea? Thanks.
  2. Which server are you using? This is usually an extension feature.
    In websphere, you edit the deployment descriptor and check the "Shared Session Context" checkbox and voila.
    In tomcat, you put something like this in the server.xml <Context path="/myapp" docBase="/home/web/myapp'" crossContext="true" debug="0" reloadable="false" trusted="false" />

    The crossContext="true" makes sure that the session is shared.
    Look at your app server's manual for exact details.
  3. Hi Dushyanth,

    Thanks a lot for your reply.
    I am using WebSphere portal server. Does "Shared Session Context" mean mutiple wars(applications) use the same session, no matter which war creates the session?
  4. You can use proprietary extension or instead be more portable by seeing the two web applications as separated and so do what two partners having different web site normally do. I'm sure they are many ways, one of them is sending a normal http request to the second web server will all the information you want to pass!

    So the proprietary side, the web applications normally share some base classloader at least the JVM one, so you can have a singleton at this level that's used to pass information around.
  5. Thanks Sébastien. We are using the solution just like yours.