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

[382 byte] By [jean-philippea] at [2007-10-3 2:27:40]
# 1

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

serlanka at 2007-7-14 19:26:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
"G閚ial"Thanks, it's working!
jean-philippea at 2007-7-14 19:26:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

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

brian@cubik.caa at 2007-7-14 19:26:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...