Java后端压缩-浏览器解压缩

本文介绍了在Java后端使用Tomcat配置实现HTTP响应的gzip压缩,以提高数据传输速度。同时,展示了如何在Java代码中对传输的数据进行压缩,包括统一定义的压缩工具类和设置HTTP响应头的Content-Encoding。最后,提供了两个参考链接以深入理解gzip压缩。
摘要由CSDN通过智能技术生成

前言:

The next version of the Project will provide support for gzip in order to faster speed of data transmission on the network。

在我们的项目中,添加对gzip的支持,是为了加快数据在网络中的传输速度。

If you need to transfer data using gzip, you must be setting request header "Accept-Encoding"="gzip". Thus,  you will get a response, which include the response header name "Content-Encoding" and value "gzip", and need to ungzip the response data. Besides, the response header name "Content-Length" also will be returned.使用gzip,首先要设置请求消息头Accept-Encoding为gzip。

这样,你将会得到一个响应,根据消息头Content-Encoding为gzip你可以知道,传输过来的数据是经过gzip压缩的。另外,消息头Content-Length会告诉你压缩后的数据长度。

 

正文:

一:仅使用tomcat配置进行相关压缩

(注:仅使用tomcat压缩仅对页面进行压缩,而后端传输数据并没有进行任何压缩)

1.1配置部分

tomcat配置前

<Connector port="8080" protocol="HTTP

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值