Forward a request with post data to another webApp
Hello,
I have a servlet that recieves data by post. I need to forward that request with the same info it recieves to another webApp in a different EAR
I know it is possible to forward that request to another servlet in the same webapp, how to do that but to a different webApp in post method (No get method, do no sendRedirect)?
Thanks.
Jean-Philippe
There's a method called getContext(String) in the ServletContext class, so if you have a reference to the context of the current webapp you could try something like :
ServletContext otherContext = context.getContext("/otherWebApp");
RequestDispatcher dispatcher = otherContext.getRequestDispatcher("/otherServlet");
dispatcher.forward(request, response);
> > ServletContext otherContext =
> context.getContext("/otherWebApp");
> RequestDispatcher dispatcher =
> otherContext.getRequestDispatcher("/otherServlet");
>dispatcher.forward(request, response);
>
Interesting. If I read this correctly you CAN actually use RequestDispatcher.forward() to redirect a user after they've contacted the web-server? i.e. Using the otherContext will cause the response that the web-server generates to come from /otherWebApp? That's cool...
Brian