如何在另一个 Web 应用程序上下文中访问一个 Web 应用程序上下文 [英] How to access the one Web application Context in another Web application Context

查看:37
本文介绍了如何在另一个 Web 应用程序上下文中访问一个 Web 应用程序上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Tomcat6 服务器中部署了两个 WAR,例如 WAR-AWAR-BContext-AContext-B 分别.

I have deployed two WAR's in a Tomcat6 server, Say for example WAR-A, WAR-B in Context-A and Context-B respectively.

我在 Context-A 中存储了一些数据,我想在 Context-B 中读取这些数据.

I've stored some data in Context-A, and I want to read that data in Context-B.

我已经通过网络并找到了一些方法来实现它.我通过 cookie 使 Context-A 的会话 ID 可用于所有上下文.我也在 server.xml 中设置了 crossContext = true .

I have gone through the net and got some way to acheive it. I make the session ID of Context-A available for all the contexts by cookies. And I have set the crossContext = true in server.xml too.

但是当我在 Context-B 中执行 serveltContext.getContext("Context-A"); 时,它返回 null.

But when I do serveltContext.getContext("Context-A"); in Context-B it's returning null.

推荐答案

Context-A"不正确.传递给 getContext 的参数 是一个uripath".所以如果你有 WAR-A (/war-a) 和 WAR-B (/war-b) 来自 WAR-B 的调用应该是

The "Context-A" is incorrect. The parameter passed to getContext is a "uripath". So if you have WAR-A (/war-a) and WAR-B (/war-b) the call from WAR-B should be

servletContext.getContext("/war-a");

<小时>

注意:我为 getContext 发布的链接来自 Java EE 1.3 API,但它不应该改变.


Note: the link I posted for getContext was from the Java EE 1.3 API, but it should not have changed.

这篇关于如何在另一个 Web 应用程序上下文中访问一个 Web 应用程序上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆