RequestDispatcher operates within a given ServletContext (web application).
You are trying to do a cross-context dispatch - i.e. to another web
application. To do this you will need to:
- enable cross-context dispatch for the /plugins web application
https://tomcat.apache.org/tomcat-8.5-doc/config/context.html
look for crossContext
- then use code something like this:
ServletContext current = request.getServletContext();
ServletContext backend = current.getContext("/backend");
RequestDispatcher rd = backend.getRequestDispatcher("/rest/abc/xx");
rd.forward(request,response);
HTH,
Mark
On 11/08/2023 08:52, Andy Pont wrote:
Hello!
We have a commercial application that runs under Tomcat 8.5.65 (on
Windows Server 2019). In the tomcat/webapps directory there are the
following three directories (names changed):
backend
frontend
ROOT
The “frontend” directory contains the UI for the commercial application
and is, as far as I can tell, all just HTML, JavaScript, etc. The
“backend” directory contains the parts of the system that do the bulk of
the work and appear to be mainly .jsp files.
Amongst other things, the “backend” handles a URL
https://<server_name>/backend/rest/abc/xx where “xx” represents a number
that tells it what to act upon.
I have started developing a new servlet which handles POST requests to
the URL: https://<server_name>/plugins/abc/xx. In some cases (based on
a values in the request body), the servlet will process things itself
and generate its own response. For certain cases it just needs to
forward the request on to corresponding “backend” URL and then pass the
response back.
I assumed that .forward(request, response) on a RequestDispatcher would
be what I needed to use. I have tried every combination of
getServletContext() and getRequestDispatcher() I can think of or have
found on the internet but it always fails with an HTTP error 404. This
is because the URL that it is being forwarded to always has a rogue
“plugins” in it, i.e. https://<server_name>/plugins/backend/rest/abc/xx.
I suspect the solution is simple but I am new to Tomcat and developing
servlets and probably missing something obvious. Any guidance would be
much appreciated.
-Andy.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org