tomcat 添加gzip压缩

页面

<meta http-equiv="accept-encoding" content="gzip,deflate">


在tomcat中配置gzip的方法是在conf/server.xml文件中把以前的配置修改成


<Connector
port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" />

compression="on" 打开压缩功能
compressionMinSize="2048" 启用压缩的输出内容大小,这里面默认为2KB
noCompressionUserAgents="gozilla, traviata" 对于以下的浏览器,不启用压缩;
compressableMimeType="text/html,text/xml" 压缩类型

在tomcat/webapps/工程/WEB-INF/web.xml中增加下面的配置

<mime-mapping>

<extension>conf</extension>

<mime-type>text/plain</mime-type>

</mime-mapping>

<mime-mapping>

<extension>CONF</extension>

<mime-type>text/plain</mime-type>

</mime-mapping>


<mime-mapping>

<extension>ini</extension>

<mime-type>text/plain</mime-type>

</mime-mapping>

<mime-mapping>

<extension>INI</extension>

<mime-type>text/plain</mime-type>

</mime-mapping>


<mime-mapping>

<extension>png</extension>

<mime-type>image/png</mime-type>

</mime-mapping>

<mime-mapping>

<extension>PNG</extension>

<mime-type>image/png</mime-type>

</mime-mapping>


<mime-mapping>

<extension>gif</extension>

<mime-type>image/gif</mime-type>

</mime-mapping>

<mime-mapping>

<extension>GIF</extension>

<mime-type>image/gif</mime-type>

</mime-mapping>


<mime-mapping>

<extension>json</extension>

<mime-type>text/plain</mime-type>

</mime-mapping>

<mime-mapping>

<extension>JSON</extension>

<mime-type>text/plain</mime-type>

</mime-mapping>


<mime-mapping>

<extension>xml</extension>

<mime-type>text/xml</mime-type>

</mime-mapping>

<mime-mapping>

<extension>XML</extension>

<mime-type>text/xml</mime-type>

</mime-mapping>



<mime-mapping>

<extension>dll</extension>

<mime-type>application/x-msdownload</mime-type>

</mime-mapping>

<mime-mapping>

<extension>DLL</extension>

<mime-type>application/x-msdownload</mime-type>

</mime-mapping>


配置后的头文件你会发现成这样了

1.响应头信息

Server Apache-Coyote/1.1
Set-Cookie JSESSIONID=072D9B189C4AA9DA4D4AD0B6C2C89E50; Path=/test
Content-Type text/html;charset=ISO-8859-1
Transfer-Encoding chunked
Content-Encoding gzip
Vary Accept-Encoding
Date Mon, 04 Jan 2010 04:49:38 GMT
2.请求头信息
Host localhost:8080
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language zh-cn,zh;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
Cookie JSESSIONID=1C8DB59AC74495495ED374B13C3D930A
Cache-Control max-age=0

没有配之前为


1.响应头信息
Server Apache-Coyote/1.1
Content-Type text/html;charset=ISO-8859-1
Transfer-Encoding chunked
Date Mon, 04 Jan 2010 04:54:00 GMT
请求头信息
Host localhost:8080
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language zh-cn,zh;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
Cookie JSESSIONID=072D9B189C4AA9DA4D4AD0B6C2C89E50
Cache-Control max-age=0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值