Tomcat 中的 crossContext 属性有什么作用? 它是否启用会话共享?
我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 在 Web 应用程序之间共享会话单点登录阀。
如果您想在同一虚拟主机中的不同 Web 应用程序之间共享一些信息,您可以设置
crossContext=true
。例如,app1 会调用:
,另一个应用程序可以调用
来读取信息。 如果 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:
and another app could call
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.
来自 javadoc
ServletContext.getContext()
:例如,如果您想包含来自不同 Web 应用程序的页面,您需要将 crossContext 设置为 true。
From the javadoc
ServletContext.getContext()
:So for instance if you want to include a page from a different webapp you need to set crossContext to true.
我自己尝试过,但找不到神奇的会话共享副作用,因此 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.