RequestDispatcher在Tomcat实例之间转发 [英] RequestDispatcher forward between Tomcat instances
问题描述
我有一个场景,我有单个入口点Servlet和进一步的Servlet请求被转发到进行繁重处理。
我正在寻找分发这个的选项加载,我想知道是否有可能使用Tomcat或其他平台在使用集群类型配置或类似设置的不同服务器上的Servlet之间转发请求。
我有发现了一些关于集群Servlet和Tomcat的文档,但没有一个表明我是否可以看到Servlet请求转发。
http://tomcat.apache.org/tomcat-5.5-doc/cluster-howto.html
您可以通过群集Tomcat环境中的webapps进行分发,并将 crossContext =true
添加到< Context>
相关网络广告的元素。以下是 Tomcat的上下文配置参考的摘录:
crossContext
设为
true
如果你想在这个应用程序中调用ServletContext.getContext()
成功返回运行其他Web应用程序的请求调度程序在这个虚拟主机上。在安全意识环境中设置为false
(默认值),使getContext()
始终返回null
。
这样您就可以获得所需的 RequestDispatcher
如下:
RequestDispatcher dispatcher = getServletContext()。getContext(name).getRequestDispatcher(path);
I have a scenario where I have single entry point Servlet and further Servlets that requests are forwarded to that undertake heavy processing.
I am looking at options to distribute this load and I would like to know if it is possible using Tomcat or another platform to forward requests between Servlets sitting on different servers using a cluster type configuration or similar.
I have found some documentation on clustering Servlets and Tomcat but none indicate if Servlet request forwarding is possible from what I can see.
http://tomcat.apache.org/tomcat-5.5-doc/cluster-howto.html
You could distribute it over webapps in a clustered Tomcat environment and add crossContext="true"
to the <Context>
element of the webapps in question. Here's an extract of Tomcat's Context Configuration Reference:
crossContext
Set to
true
if you want calls within this application toServletContext.getContext()
to successfully return a request dispatcher for other web applications running on this virtual host. Set tofalse
(the default) in security conscious environments, to makegetContext()
always returnnull
.
This way you can obtain the desired RequestDispatcher
as follows:
RequestDispatcher dispatcher = getServletContext().getContext(name).getRequestDispatcher(path);
这篇关于RequestDispatcher在Tomcat实例之间转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!