[英]Obtain servlet response when using Cross-Context
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'. 我正在使用跨上下文调用另一个服务器应用程序中的servlet:服务器应用程序“ A”中的Servlet / bar调用服务器应用程序“ B”上的/ foo servlet。
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. 我正在使用这个非常好的解决方案,就像Abhijeet Ashok Muneshwar的答案一样 ,我将请求从服务器应用程序A转发到服务器应用程序B上的/ foo servlet。
I'm using the class RequestDispatcher () to send a request, but the response is returned in the same call? 我正在使用类RequestDispatcher()发送请求,但响应是在同一调用中返回的?
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. 如何处理A的Servlet中的服务器应用程序B并从中返回响应。
Thanks. 谢谢。
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.
RequestDispatcher的另一个选项是进行包含。
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. 如果您想要更多的控制权,则必须使用HTTP客户端来检索响应,然后应用所需的任何处理,但是我不建议您使用HTTP客户端这种方式。 You'd be better off refactoring your application so you can use RequestDispatcher.include.
最好重构应用程序,以便可以使用RequestDispatcher.include。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.