zoukankan      html  css  js  c++  java
  • 服务器将数据以压缩的形式,返回给浏览器

    servlet的实现

    //压缩输出
    public class ServletDemo2 extends HttpServlet {
    
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            String data = "aaaaaaaa";
            
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            GZIPOutputStream gout = new GZIPOutputStream(bout);
            gout.write(data.getBytes());
            gout.close();
            
            
            byte gzip[] = bout.toByteArray();
            response.setHeader("content-encoding", "gzip");
            response.setHeader("content-length", gzip.length + "");
            
            response.getOutputStream().write(gzip);
            
            
        }
    
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            doGet(request, response);
        }
    
    }
  • 相关阅读:
    平衡数问题
    重复值判断练习题
    小范围排序
    堆排序
    基数排序
    计数排序
    希尔排序
    快速排序
    Effective C++笔记:实现
    Effective C++笔记:设计与声明
  • 原文地址:https://www.cnblogs.com/zhangbaowei/p/4730888.html
Copyright © 2011-2022 走看看