2

In my web application, I have two servlets as Servlet A and Servlet B. There is call to Servlet A from browser. Servlet A invokes Servlet B using RequestDispatcher calling include() method.

Servlet B writes some bytes on ServletOutputStream.

Now to the next line of include() method I want to read bytes wrote by Servlet B. How I can?

Abstract of code is as bellow.

public class A extends HttpServlet {
   protected void doGet(HttpServletRequest request, HttpServletResponse response) {
     RequestDispatcher rd = request.getRequestDispatcher("/B");
     rd.include(request, response);

    // Now here i want to read bytes of ServletOutputStream for further processing
    // How do I?

   }
}

Again I certainly cannot modify code of servlet B. It is predefined. Secondly it is sure that servlet B writes bytes on ServletOutputStream.

Any help is really apprreciated.

Hanmant
  • 4,628
  • 2
  • 18
  • 21
  • `rd.include(request, response)` will not cause Servlet `B` to write out it's response. It will only _include_ Servlet `B`'s response in Servlet `A`'s. Is committing Servlet `A`s response and then reading a possibility for you? – Sahil Muthoo Sep 12 '11 at 12:11

1 Answers1

1

You should have a look at HttpServletResponseWrapper. Have a look for more info here and here

Community
  • 1
  • 1
Kris
  • 5,714
  • 2
  • 27
  • 47
  • Thank you Kris, I went through HttpServletResponseWrapper and resolved my issue in conjunction with ServletFilter :) – Hanmant Sep 21 '11 at 09:30