0

I am interested to ask... Is it possible to keep session between TWO war(s) on ONE web server. For example there are

  • A) war file A
  • B) war file B

    war file A has

...

String aText="Hello World";
session.setAttribute("anAttribute",aText);

...

so my question is... Can I call code like a

String fromAWarFile=session.getAttribute("anAttribute");

... from war file B to get "Hello World" value of war file A?

Any useful comment is appreciated

user592704
  • 3,674
  • 11
  • 70
  • 107

3 Answers3

0

No, the servlet spec forbids this. All WARs must be selfcontained. Maybe a portal software may help you. You either have to create a shared store or resort to your container's features which might support that.

Michael-O
  • 18,123
  • 6
  • 55
  • 121
0

Well, it is not advisable to use shared session between two WARs, still you can achieve by maintaining a common cache or so. You need to create a wrapper class of HttpSession which will contain an API to get updated info from the cache. You can decide how frequently or based on which even you want to update your session.

Partha
  • 572
  • 1
  • 9
  • 17
  • It is OK because I am going to do that on local machine so there is no outer network expected. Anyway, is it possible to limit access with servlet controller then? – user592704 Jul 27 '11 at 20:25
0

I think what you are looking for is session clustering http://www.ibm.com/developerworks/java/library/j-jtp07294/index.html, I think all the major servlet containers support this.

Here is the documentation from tomcat http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html

Prasanna Talakanti
  • 2,354
  • 1
  • 16
  • 16
  • So I can share attributes' values between war files during web-container is running? – user592704 Jul 27 '11 at 20:27
  • If you do the session clustering you can, It involves configuring your servlet container and also some code, I would suggest you to get some understanding on HttpSessionBindingListener http://download.oracle.com/javaee/1.3/api/javax/servlet/http/HttpSessionBindingListener.html – Prasanna Talakanti Jul 27 '11 at 20:36
  • OK, I'll try it and report my results – user592704 Jul 28 '11 at 17:53
  • I just wanted to ask... I want to share session in just ONE web-container but the samples from http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html talk about TomcatA and TomcatB :( But I am going to have just ONE Tomcat so do I need clustering then? – user592704 Jul 29 '11 at 15:46
  • I watched the example as http://www.fwd.at/tomcat/sharing-session-data-howto.html but it describes the URL and Cookey controls but is it the only way? – user592704 Jul 29 '11 at 16:02
  • I guess it is more or less accepted way to use session cookies (I do that in my web applications). If you want to do with out cookies then might have search google for session management with out cookies, I have not done that so I can't be any help on that issue. – Prasanna Talakanti Jul 29 '11 at 16:38