皮皮网

【管道线主图指标公式源码】【github抽奖源码】【macoswifi驱动源码】httpservletresponse源码

2024-11-30 06:59:06 来源:免费amcd源码

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;

        }

        }

       }