ITPub博客

首页 > 应用开发 > Java > 设置ear中war之间session共享

设置ear中war之间session共享

Java 作者:xz43 时间:2014-03-21 16:59:02 0 删除 编辑

Web规范中规定每个Web应用的Session信息彼此是不能共享的,但是在开发Web应用时,有时我们希望多个Web应用之间可以共享Session信息。
但是现在大部分J2EE服务器,都实现了EAR中war之间的session共享,如weblogic(>=9)、websphere。
因此,我们可以把多个war打到一个EAR里面,来实现war直接的Session共享。

设置weblogic的EAR中war之间session共享有下面两种方法:

1:设置EAR中的weblogic-application.xml文件,加入如下片段:

   
  memory
  true
 

 
整个weblogic-application.xml内容如下:

http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
    10.0
    testEARweb2
   
  memory
  true
 

2.设置需要共享session的war内的weblogic.xml文件,例如testEAR内有两个war,testEARweb1和testEARweb2,想让这两个war之间session共享,
则需要设置这两个war里面的weblogic.xml文件,同样,加入下面片段即可:
   
  memory
  true
 

设置后testEARweb1的weblogic.xml内容如下:


http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
    10.0
    testEARweb1
   
  memory
  true
 


 
testEARweb2的weblogic.xml内容如下: 

http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
    10.0
    testEARweb2
   
  memory
  true
 

这样,EAR内的war之间就可以共享session了。

对于WAS,需要设置ibm-application-ext.xmi文件,

http://www.omg.org/XMI" xmlns:applicationext="applicationext.xmi" xmlns:application="application.xmi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmi:id="Application_ID_Ext" sharedSessionContext="true"> 

其中sharedSessionContext="true",就是说明要开启共享session。

可以参考:http://maping930883.blogspot.jp/2009/03/wls056earwebsession.html

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9399028/viewspace-1126886/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
鱼儿的学习空间

注册时间:2010-11-16

  • 博文量
    433
  • 访问量
    1863899