2

Could you please help me in reading a servlet output by using a java class/servlet. Scenario : I have a servlet which prints "Hello World" say from out.println("Hello World).

I need to capture the output of that servlet in a java/servlet file and perform a task

Appreciate for any leads on this.

Thanks

pal
  • 1,022
  • 4
  • 15
  • 27

2 Answers2

2

if out is the response stream then you can make call using HttpURLConnection to read the output it prints on response.

See Also

Community
  • 1
  • 1
jmj
  • 225,392
  • 41
  • 383
  • 426
0

We can use filters. And after "chaining" we can use response object to read the response string.

chain.doFilter(request, response);

There is a similar question with full description. As it contains an extensive description, I am not repeating it here again.

Community
  • 1
  • 1
Ashish Agarwal
  • 5,781
  • 12
  • 53
  • 86
  • You forgot one important additional step. There is no standard way to read the body from `HttpServletResponse` directly. There's no `getInputStream()` method or something. – BalusC Sep 08 '11 at 12:18