欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
tomcat 中的gzip壓縮配置
#

這兩篇文章主要介紹在apache http server下如何使用mod_deflate模塊來(lái)壓縮http響應內容,最大限度的減小網(wǎng)絡(luò )流量,然而當我們僅僅是使用tomcat服務(wù)器時(shí)候,更多的文章是通過(guò)自行編寫(xiě)一些代碼來(lái)實(shí)現輸出內容的壓縮,其實(shí)tomcat本身在5.0版本以后是支持內容壓縮的,它使用的是gzip的壓縮格式,我們先來(lái)看 Tomcat文檔中對下面兩個(gè)配置的注解(紅色粗體字部分)

compressableMimeType

The value is a comma separated list of MIME types for which HTTP compression may be used. The default value is text/html,text/xml,text/plain.

compression

The Connector may use HTTP/1.1 GZIP compression in an attempt to save server bandwidth. The acceptable values for the parameter is "off" (disable compression), "on" (allow compression, which causes text data to be compressed), "force" (forces compression in all cases), or a numerical integer value (which is equivalent to "on", but specifies the minimum amount of data before the output is compressed). If the content-length is not known and compression is set to "on" or more aggressive, the output will also be compressed. If not specified, this attribute is set to "off".

這兩個(gè)配置是在servere.xml中的Connector部分,第一個(gè)配置是指定Tomcat壓縮哪些內容,第二個(gè)配置是指示Tomcat是否啟用壓縮,默認是關(guān)閉的。所以假設我們要讓Tomcat在默認的8080端口上的輸出內容進(jìn)行壓縮,我們的配置應該是:

    <Connector port="8080" protocol="HTTP/1.1"
               maxThreads="150" connectionTimeout="20000"
               redirectPort="8443" compression="on"/>

一旦啟用了這個(gè)壓縮功能后,我們怎么來(lái)測試壓縮是否有效呢?首先Tomcat是根據瀏覽器請求頭中的accept-encoding來(lái)判斷瀏覽器是否支持壓縮功能,如果這個(gè)值包含有g(shù)zip,就表明瀏覽器支持gzip壓縮內容的瀏覽,所以我們可以用httpclient來(lái)寫(xiě)一個(gè)這樣的簡(jiǎn)單測試程序

package com.liusoft.dlog4j.test;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;

/**
 * HTTP客戶(hù)端測試類(lèi)
 * @author liudong
 */
public class HttpTester {

 /**
  * @param args
  */
 public static void main(String[] args) throws Exception{
  HttpClient http = new HttpClient(); 
  GetMethod get = new GetMethod("http://www.dlog.cn/js/prototype.js");
  try{
   get.addRequestHeader("accept-encoding", "gzip,deflate");
   get.addRequestHeader("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Alexa Toolbar; Maxthon 2.0)");
   int er = http.executeMethod(get);
   if(er==200){
    System.out.println(get.getResponseContentLength());
    String html = get.getResponseBodyAsString();
    System.out.println(html);
    System.out.println(html.getBytes().length);
   }
  }finally{
   get.releaseConnection();
  }
 }

}

執行這個(gè)測試程序,看看它所輸出的是什么內容,如果輸出的是一些亂碼,以及打印內容的長(cháng)度遠小于實(shí)際的長(cháng)度,那么恭喜你,你的配置生效了,你會(huì )發(fā)現你網(wǎng)站的瀏覽速度比以前快多了。

另外你最好對網(wǎng)站所用的javascript和css也進(jìn)行壓縮:)
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
關(guān)于http gzip壓縮的一點(diǎn)想法
關(guān)于Tomcat GZip的疑問(wèn) - JavaEye問(wèn)答
JAVA利用httpclient登錄開(kāi)心網(wǎng)
用HttpClient來(lái)模擬瀏覽器GET POST
運用Apache HttpClient實(shí)作Get與Post動(dòng)作 - 小嘴冰涼 - ITey...
HttpClient容易忽視的細節
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久