求助:jsp中session跨war包调用问题?

wyj_cn2000 03-09-19

各位高手,现在急需解决怎样实现jsp中session跨war包调用。在同一war包内session没有问题,只要跨war包session中就为空值,请问如何解决?web应用服务是weblogic7.0

banq
2003-09-21 18:41

这可能需要Session的cluster功能,好像Tomcat有,你参考一下。

Jevang
2003-09-22 01:46

I was bothered by the same problem when I was playing multiple wars in a signle EAR file. Here is my understanding:
Each WAR has its own Context, it maintains its own Session, and each Context keeps track its sessions thru cookies, but the default "PATH" is bound to one particular context, so browser won't send the cookie issued from one Context to another Context in its request.
given that, I hard coded the jsessionid coming from first Context in the URL when sending request to second Context( I think a better way is construct your own cookie, make PATH global ). In the server code, I capture the JsessionId( issued by another session), now I can use HttpSessionContext.getSession( sid) to get another session created by another Context, and read data from it. HttpSessionContext.getSession is deprecated, but you can share session thru your own singleton or ServletContext, same thing. The key here is having the jsessionid about another session.

Cluster has no help but invalid the solution above which works well under single install. Rescue is you either enable fail-over or persistent the data by code. I never tried to setup a container enabled fail-over, none of the real projects I see need it.

Eventually it falls back to a single WAR solution for me as I ran into classloading issues and I was run out of interests in exploring technology spec/tricks. This was long time back I did but hope my experience helps you.

-Jevang



wys1978
2003-09-22 16:15

不同的war就是不同的web application, 根据j2ee规范session是不能被跨web app调用的,quote:

Session information is scoped only to the current web application (ServletContext), so information stored in one context will not be directly visible in another.

我在以前的项目中也碰到过有这样的需求,要求2个不同的web app可以共享其session attribute,后来是采用cookie解决的,因为cookie可以设置path为global,这样不同的web app都可以读到同一cookie属性。

wyj_cn2000
2003-09-23 09:56

thanks