0

I'm using cross-context to call a servlet in another server application: Servlet /bar from server application 'A' calls /foo servlet on server application 'B'.

I'm using this very nice solution, just as in the Abhijeet Ashok Muneshwar answer, I forward the request from server application A to the /foo servlet on server application B.

I'm using the class RequestDispatcher () to send a request, but the response is returned in the same call?

RequestDispatcher rd = context.getRequestDispatcher("/Servlet2");
rd.forward(request, response);

How can I process and return the response from server application B in A's servlet.

Thanks.

Community
  • 1
  • 1
user2256799
  • 229
  • 1
  • 3
  • 10

1 Answers1

2

If you use a forward, that passes control to the target of the forward. The other option with a RequestDispatcher is to do an include.

If you want more control than that, you'll have to use an HTTP client to retrieve the response and then apply whatever processing you want to but using an HTTP client this way is not something I'd recommend. You'd be better off refactoring your application so you can use RequestDispatcher.include.

Mark Thomas
  • 16,339
  • 1
  • 39
  • 60
  • Right. I now realize that the servlet who generates the response is the one you call using the RequestDispatcher. This just works for me, since I do not need to do any processing to this response. Thanks Mark. – user2256799 Dec 22 '15 at 06:20