Original address: http://benx.iteye.com/blog/561998
The method of configuring Gzip in Tomcat is to modify the previous configuration in the Conf/server.xml file to
Java code
- <connector
- port= "8080" maxhttpheadersize="8192 "
- maxthreads= "minsparethreads=" "maxsparethreads= "
- enablelookups="false" redirectport="8443" acceptcount="
- connectiontimeout="20000" disableuploadtimeout="true"
- compression="on"
- compressionminsize="2048"
- nocompressionuseragents="Gozilla, Traviata"
- Compressablemimetype="Text/html,text/xml,text/javascript,text/css,text/plain"/>
- />
Tested before the compression of the size of 1.5M after compression only 10K, may be and have a lot of duplication of data about, response speed also has the previous 2.5 seconds to 275ms
Configured header file you'll find that out.
HTML code
- Response header Information
- 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, Jan 04:49:38 GMT
- Request header Information
- 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
No match before the
HTML code
- Response header Information
- Server apache-coyote/1.1
- Content-type text/html; charset=iso-8859-1
- Transfer-encoding chunked
- Date Mon, Jan 04:54:00 GMT
- Request header Information
- 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
In JSP, the default is to use the cache, if you do not want to use the JSP page can be added
Java code
- <%
- Response.setheader ("Pragma","No-cache");
- Response.setheader ("Cache-control","No-cache");
- Response.setdateheader ("Expires", 0);
- %>
Note that this is only for pages that do not use caching, images, CSS, JS, or you can use the cached
If you want to control a type that does not use the cache, you can use the filter
Tomcat with Gzip and cache