RequestDispatcher在Tomcat实例之间转发 [英] RequestDispatcher forward between Tomcat instances

查看:134
本文介绍了RequestDispatcher在Tomcat实例之间转发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景,我有单个入口点Servlet和进一步的Servlet请求被转发到进行繁重处理。



我正在寻找分发这个的选项加载,我想知道是否有可能使用Tomcat或其他平台在使用集群类型配置或类似设置的不同服务器上的Servlet之间转发请求。



我有发现了一些关于集群Servlet和Tomcat的文档,但没有一个表明我是否可以看到Servlet请求转发。



http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html



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://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html

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 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.

This way you can obtain the desired RequestDispatcher as follows:

RequestDispatcher dispatcher = getServletContext().getContext(name).getRequestDispatcher(path);

这篇关于RequestDispatcher在Tomcat实例之间转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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