RequestDispatcher forward between Tomcat instances

Deadly 提交于 2020-01-12 05:44:06

问题


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


回答1:


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);


来源:https://stackoverflow.com/questions/2815370/requestdispatcher-forward-between-tomcat-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!