Will request.getDispatcher("/newurl").forward() work when using apache connected to tomcat via ajp?

852 Views Asked by At

I was trying to change the behaviour of a 3rd party app I'm working with by writing a servlet filter to forward a request to a particular URL based on certain conditions.

I initially tried with request.getDispatcher(url).forward(); but was always presented with a 404 page showing that url couldn't be found. I got around this by using request.sendRedirect instead, but it's only now that I realise the 404 screen was what I commonly see server up by tomcat.

That got me to thinking about the configuration in this instance. The url I'm trying to forward to is a cgi script. We have apache as a front end connected via ajp connectors and apache is configured to execute cgi scripts.

So my question is, did the foward from the servlet filter ever make it to apache, or is the forward handled by tomcat specifically and that's why it wouldn't work?

1

There are 1 best solutions below

1
On BEST ANSWER

did the foward from the servlet filter ever make it to apache

No. RequestDispatcher.forward is an internal operation within the appserver's webapp, used to transfer flow control from one internal component (e.g. a servlet) to another (e.g. a JSP). You cannot forward to resources outside of the appserver, like your CGI script. You'll have to use a redirect for that.