附件源代码
不过采用resin服务器的话,以上代码会失效。因为resin没有实现getWriter方法,而是采用getOutputStream取而代之,所以必须修改些代码来迎合resin运行环境:
/** * 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 */ |
 
2/2 首页 上一页 1 2 |