Inside a Java servlet, how can I forward the user to a specific URL? For example, my servlet is here:
https://www.mydomain.com/myJavaServlet
and after some business logic, I want to forward the user to this URL:
https://www.mydomain.com/myFile.pdf#nameddest=Chapter3
but in the user's browser, the following URL must be present:
https://www.mydomain.com/myJavaServlet
because the forwarded URL must remain hidden. I think that's the concept behind forwarding (let me know if not).
UPDATE 1:
Why doesn't the following work?
req.getRequestDispatcher("https://www.mydomain.com/myFile.pdf#nameddest=Chapter3").forward(req, res);
UPDATE 2:
The following doesn't give error in browser, it just hangs:
String url = "https://www.mydomain.com/myFile.pdf";
RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher(url);
requestDispatcher.forward(req, res);
If I place the pdf in the web app directory and try
String url = "/WEB-INF/myFile.pdf";
then the browser opens its PDF reader, but no file gets loaded into the reader (it's empty).
If I replace the 2nd line in UPDATE2 above with
RequestDispatcher requestDispatcher = req.getRequestDispatcher(url);
I get similar results for the two url strings as reported above for UPDATE 2.