This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Questions re: response.getOutputStream() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Questions re: response.getOutputStream()" Watch "Questions re: response.getOutputStream()" New topic

Questions re: response.getOutputStream()

Richard Olson

Joined: Mar 15, 2004
Posts: 15


I'm a newbie try to complete the following goal. We need a utility for capturing or intercepting HTTP responses then writing the output to a file for troubleshooting purposes; something like a sniffer, but without packet info.

I've tried various methods, but so far no success. I�ve tried using ServerOutputStream sOutStr = response.getOutputStream(). How do I write the output to a file? No write methods exist for writing ServerOutputStream to a file. I looked at some of the other streams, but none seem to fit my purposes or I missed the boat.

Any ideas because I�m confused. Hopefully, my description makes sense.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

The typical approach (which isn't real friendly to newbies) is to wrap the response in an instance of HttpServletResonseWrapper and override the methods needed to alter the response's behaviour.

I have a rough example of this on my site:

In it the response is captured in a filter and written to stdout.
I could be altered very easily to write the output to file.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Richard Olson

Joined: Mar 15, 2004
Posts: 15
Thanks, Ben, I'll take a look
subject: Questions re: response.getOutputStream()
Similar Threads
JSp Output to PDF
Can use JSP to deliver a non-text file?
Empty Downloaded zip file
Hibernate 3.x and Data Dump
how to test struts action class