Shared session between Web Modules
Hi, it is possible to share the same session between web modules or applications?... for example, i have developed a tiny code where it shows your current id session:
HttpSession S=(HttpSession)getExternalContext().getSession(true);
lblSession.SetText(S.getId());
nothing fancy about it.
So this web module on SJSAS is called "X", and when i launch this application (http://localhost:8080/X/) it shows my current session ID and a link to ANOTHER web application called "Y" (http://localhost:8080/Y/ ) which it has exactly the same code as above but just different name(from X to Y), so it does the same thing... but when i run the second module, the id session that throws is different from the first one, the id session (and therefore the whole session thing) is different between applications, between web modules. So, is there a way to make a session endure across web applications? Or what am i doing wrong? I Really need ADVICE.
[964 byte] By [
Elessar] at [2007-11-26 8:28:51]

# 2
> What you want to achieve is forbidden by servlet
> spec("SRV.7.3 Session Scope"). Sessions can not be
> shared between different web applications.
Well, that's true, it's impossible (by the servlet specification) to share session data across web modules. But i found a workaround, we ( my development team and myself ) managed to administrate the session entity across diferent and multiple web applications using cookies. After all that wasn't too hard but it freaked me out for a while... if you want details on this issue just ask for it and i will gladly provide the info.
Greetings.
# 4
hi Elessar,
i would like to know how you implemented the session attributes sharing across different apps using cookies. would you mind sharing it with me?
we're migrating apps from iPlanet 6.5 to SJS App server 8.1 and we do not know how to solve the session problem.
thanks and hope to hear from you soon.
# 5
> hi Elessar,
>
> i would like to know how you implemented the session
> attributes sharing across different apps using
> cookies. would you mind sharing it with me?
> we're migrating apps from iPlanet 6.5 to SJS App
> server 8.1 and we do not know how to solve the
> session problem.
>
> thanks and hope to hear from you soon.
Hi k_obispo. In the days to come, i'll put here some code explaining the procedure...
Greetings to all the Java Community.
# 6
We can share data among web applications using ServletContext.
In the web application to be shared data:
ServletContext myContext = servlet.getServletContext();
myContext.setAttribute("someName", someObject);
In the web application want to get data:
ServletContext firstOne = servlet.getServletContext().getContext("/FirstWebAppPrefix");
Object someData = (Object)firstOne.getAttribute("someName");
It works for my project.