【智慧废品回收源码免费下载】【博雅源码】【microblog 源码】httpservletresponse源码

时间:2024-11-26 10:35:26 来源:怎么玩源码教程 分类:综合

1.HttpServletResponse是智慧废品回收源码免费下载什么意思
2.获取HttpServletRequest和HttpServletResponse
3.responseJSP中的隐藏对象 -- response- -
4.如何主动创一个httpservletresponse
5.经验分享:读取HttpServletRequest和HttpServletResponse的Body时遇到的坑和解决方法
6.如何获取jsp输出内容用HttpServletResponseWrapper

httpservletresponse源码

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;

        }

        }

       }