皮皮网

【ios论坛源码下载】【python re模块源码】【社交平台 java 源码】httpservletresponse源码

时间:2024-12-29 10:21:21 来源:背源码 作者:java选课系统源码

1.HttpServletResponse是ios论坛源码下载什么意思
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;

        }

        }

       }

关键词:校园点餐小程序源码在哪

copyright © 2016 powered by 皮皮网   sitemap