1.檢查客戶(hù)端是否支持該壓縮
向客戶(hù)端發(fā)送壓縮的Web頁(yè)面,必須檢查request的Accept-Encoding報(bào)頭是否支持這種壓縮格式,如果向不支持的客戶(hù)端發(fā)送壓縮的Web頁(yè)面,那么客戶(hù)端將不能正常顯示。
2.respond必須設(shè)置報(bào)頭的Content-Encoding
如果客戶(hù)端支持該壓縮,使用該壓縮對(duì)輸出進(jìn)行包裝后,必須設(shè)置respond的報(bào)頭的編碼為該壓縮,這樣客戶(hù)端才能正確的解壓縮。
3.如果是gzip格式,必須out.close()。
PrintWriter out;
String encodeings = request.getHeader("Accept-Encoding");
String flag = request.getHeader("disableGzip")
if( ((encodings != null) && (encodings.indexof("gzip")) != -1)) &&(!((flag != null) && (!flag.equalsIgnoreCase("false")))){
out = new PrintWriter(new GZIPoutputStream(response.getOutputStream()));
response.setHeader("Content-Encoding", "gzip");
}else{
out = response.getWriter();
}
.........
.........