Tomcat 中的 crossContext 属性有什么作用? 它是否启用会话共享?

发布于 2024-07-15 11:53:53 字数 542 浏览 15 评论 0原文

我在 Tomcat 5.5 文档 中可以找到的是:

如果您希望在此应用程序中调用 ServletContext.getContext() 来成功返回在此虚拟主机上运行的其他 Web 应用程序的请求调度程序,请设置为 true。 在安全意识环境中设置为 false(默认值),以使 getContext() 始终返回 null。

我发现一些论坛帖子评论说设置 crossContext=true 还可以在不同的 Web 应用程序之间共享会话对象,但我找不到任何说明这一点的官方文档。

Servlet.getContext() 和在不同 Web 应用程序之间共享会话状态的能力之间是否存在关系?

crossContext 属性在 Tomcat 中真正有什么作用?

All I can find in the Tomcat 5.5 docs is:

Set to true if you want calls within this application to ServletContext.getContext() to successfully return a request dispatcher for other web applications running on this virtual host. Set to false (the default) in security conscious environments, to make getContext() always return null.

I've found some forum posts that comment that setting crossContext=true also enables sharing the session object between different web applications, but I'm not able to find any official docs stating this.

Is there a relation between Servlet.getContext() and the ability to share session state between different web applications?

What does the crossContext attribute really do in Tomcat?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

上课铃就是安魂曲 2024-07-22 11:53:53

您可以使用 在 Web 应用程序之间共享会话单点登录阀

如果您想在同一虚拟主机中的不同 Web 应用程序之间共享一些信息,您可以设置 crossContext=true

例如,app1 会调用:

setAttribute("name", object);

,另一个应用程序可以调用

getContext("/app1").getAttribute("name");

来读取信息。 如果 crossContext 未设置为 true,则 getContext("/app1") 将返回 null。

然而,crossContext 的使用很少见,而且可能不安全。

You can share sessions between web applications by using a Single Sign-On Valve.

You would set crossContext=true if you wanted to share some information between different Web Applications in the same Virtual Host.

For example app1 would call:

setAttribute("name", object);

and another app could call

getContext("/app1").getAttribute("name");

to read the information. If crossContext wasn't set to true, the getContext("/app1") would have returned null.

However, the use of crossContext is both rare and potentially insecure.

屋檐 2024-07-22 11:53:53

来自 javadoc ServletContext.getContext()

此方法允许 servlet 访问服务器各个部分的上下文,并根据需要从上下文中获取 RequestDispatcher 对象。 给定路径必须以“/”开头,相对于服务器的文档根进行解释,并与此容器上托管的其他 Web 应用程序的上下文根进行匹配。

例如,如果您想包含来自不同 Web 应用程序的页面,您需要将 crossContext 设置为 true。

From the javadoc ServletContext.getContext():

This method allows servlets to gain access to the context for various parts of the server, and as needed obtain RequestDispatcher objects from the context. The given path must be begin with "/", is interpreted relative to the server's document root and is matched against the context roots of other web applications hosted on this container.

So for instance if you want to include a page from a different webapp you need to set crossContext to true.

久光 2024-07-22 11:53:53

我自己尝试过,但找不到神奇的会话共享副作用,因此 crossContext 属性仅执行文档所说的操作。

我发布了另一个问题看看是否有办法共享会话状态。

I tried it myself and I can't find the magical session sharing side effect, so the crossContext attribute only does what the docs say.

I've posted another question to see if there is a way to share the session state.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文