Attachment source code
However, if the resin server is used, the above Code will become invalid. Because resin does not implement the getWriter method but uses getOutputStream instead, you must modify some code to cater to the resin runtime environment:
/*** START File FileCaptureResponseWrapper. java */ Package com. junjing. filter; Import javax. servlet .*; Import javax. servlet. http .*; Import java. io .*; Public class FileCaptureResponseWrapper Extends HttpServletResponseWrapper { Private CharArrayWriter output; Public String toString () { Return output. toString (); } Public FileCaptureResponseWrapper (HttpServletResponse response) { Super (response ); Output = new CharArrayWriter (); } Public PrintWriter getWriter () { Return new PrintWriter (output ); } Public void writeFile (String fileName) Throws IOException { FileWriter fw = new FileWriter (fileName ); Fw. write (output. toString ()); Fw. close (); } Public ServletOutputStream getOutputStream () Throws java. io. IOException { Return new ServletOutputStream (); } Public void write (int B) Throws IOException { Output. write (B ); } Public void write (byte B []) Throws IOException { Output. write (new String (B, "GBK ")); } Public void write (byte B [], int off, int len) Throws IOException { Output. write (new String (B, off, len )); } }; } Public void writeResponse (PrintWriter out) { Out. print (output. toCharArray ()); } } /*** END File FileCaptureResponseWrapper. java */ |