1.HttpServletResponse是功能最全中学网站源码什么意思
2.获取HttpServletRequest和HttpServletResponse
3.responseJSP中的隐藏对象 -- response- -
4.å¦ä½ä¸»å¨åä¸ä¸ªhttpservletresponse
5.经验分享:读取HttpServletRequest和HttpServletResponse的Body时遇到的坑和解决方法
6.å¦ä½è·åjspè¾åºå
容ç¨HttpServletResponseWrapper
HttpServletResponse是什么意思
.bobrow.framework.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
public class WrapperResponse extends HttpServletResponseWrapper {
private MyPrintWriter tmpWriter;
private ByteArrayOutputStream output;
public WrapperResponse(HttpServletResponse httpServletResponse) {
super(httpServletResponse);
output = new ByteArrayOutputStream();
tmpWriter = new MyPrintWriter(output);
}
public void finalize() throws Throwable {
super.finalize();
output.close();
tmpWriter.close();
}
public String getContent() {
try {
tmpWriter.flush(); //å·æ°è¯¥æµçç¼å²ï¼è¯¦çjava.io.Writer.flush()
String s = tmpWriter.getByteArrayOutputStream().toString("UTF-8");
//æ¤å¤å¯æ ¹æ®éè¦è¿è¡å¯¹è¾åºæµä»¥åWriterçéç½®æä½
//æ¯å¦tmpWriter.getByteArrayOutputStream().reset()
return s;
} catch (UnsupportedEncodingException e) {
return "UnsupportedEncoding";
}
}
//è¦çgetWriter()æ¹æ³ï¼ä½¿ç¨æ们èªå·±å®ä¹çWriter
public PrintWriter getWriter() throws IOException {
return tmpWriter;
}
public void close() throws IOException {
tmpWriter.close();
}
//èªå®ä¹PrintWriterï¼ä¸ºçæ¯æresponseæµåå°èªå·±æå®çè¾å ¥æµå½ä¸
//èéé»è®¤çServletOutputStream
private static class MyPrintWriter extends PrintWriter {
ByteArrayOutputStream myOutput; //æ¤å³ä¸ºåæ¾responseè¾å ¥æµç对象
public MyPrintWriter(ByteArrayOutputStream output) {
super(output);
myOutput = output;
}
public ByteArrayOutputStream getByteArrayOutputStream() {
return myOutput;
}
}
}