简体   繁体   English

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

[英]What does the crossContext attribute do in Tomcat? Does it enable session sharing?

All I can find in the Tomcat 5.5 docs is:我可以在Tomcat 5.5 文档中找到的是:

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.如果您希望在此应用程序中调用 ServletContext.getContext() 以成功地为在此虚拟主机上运行的其他 web 应用程序返回请求调度程序,则设置为 true。 Set to false (the default) in security conscious environments, to make getContext() always return null.在有安全意识的环境中设置为 false(默认值),以使 getContext() 始终返回 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.我发现一些论坛帖子评论说设置crossContext=true还可以在不同的 web 应用程序之间共享 session object,但我找不到任何官方文档应用程序。

Is there a relation between Servlet.getContext() and the ability to share session state between different web applications? Servlet.getContext() 与在不同的 web 应用程序之间共享 session state 的能力之间是否存在关系?

What does the crossContext attribute really do in Tomcat?crossContext中,crossContext 属性的真正作用是什么?

You can share sessions between web applications by using a Single Sign-On Valve .您可以使用Single Sign-On Valve在 web 应用程序之间共享会话。

You would set crossContext=true if you wanted to share some information between different Web Applications in the same Virtual Host.如果您想在同一虚拟主机中的不同 Web 应用程序之间共享一些信息,您可以设置crossContext=true

For example app1 would call:例如 app1 会调用:

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.如果 crossContext 未设置为 true,则 getContext("/app1") 将返回 null。

However, the use of crossContext is both rare and potentially insecure.然而,crossContext 的使用既罕见又可能不安全。

From the javadoc ServletContext.getContext() :从 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.该方法允许 servlets 访问服务器各个部分的上下文,并根据需要从上下文中获取 RequestDispatcher 对象。 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.给定路径必须以“/”开头,相对于服务器的文档根进行解释,并与托管在此容器上的其他 web 应用程序的上下文根匹配。

So for instance if you want to include a page from a different webapp you need to set crossContext to true.因此,例如,如果您想包含来自不同 web 应用程序的页面,您需要将 crossContext 设置为 true。

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.我自己试过了,我找不到神奇的 session 共享副作用,所以 crossContext 属性只做文档所说的。

I've posted another question to see if there is a way to share the session state.我已经发布了另一个问题,看看是否有办法分享 session state。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM