我从网上下载了个获取网页编码的程序
org.apache.commons包有了
pdetector.io包也有了
就剩下toptrack.tools.JQueryBase这个没有了,谁知道属于那个包,能给个下载地址吗
附上源代码
package com.tag;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HeaderElement;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import toptrack.tools.JQueryBase;
public class JHtmlUpdateCheck {
     private static cpdetector.io.CodepageDetectorProxy detector = cpdetector.io.CodepageDetectorProxy.getInstance();
     static {
        detector.add(new cpdetector.io.HTMLCodepageDetector(false));
        detector.add(cpdetector.io.JChardetFacade.getInstance());
     }
    public static String getEncoding(String strUrl, int timeout) {
    String strEncoding = null;
    HttpClient client = new HttpClient();
    client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);
    GetMethod method = new GetMethod(strUrl);
    method.setFollowRedirects( true );
    int statusCode;
    try {
       statusCode = client.executeMethod(method);
       if( statusCode != -1) {
         strEncoding = getContentCharSet(method.getResponseHeader("Content-Type"));
         if (strEncoding != null) {
           method.releaseConnection();
           return strEncoding;
         }
         String strHtml = method.getResponseBodyAsString().toLowerCase();
         StringBuffer strBuffer = new StringBuffer();
         int pos = JQueryBase.getTagText(strHtml, "<meta", ">", strBuffer, false, 0);
         while (strBuffer.length() > 0) {
           StringBuffer strEncodingBuffer = new StringBuffer();
           JQueryBase.getTagText(strBuffer.toString(), "charset=", "   ", strEncodingBuffer, 0);
           if (strEncodingBuffer.length() > 0) {
             strEncoding = strEncodingBuffer.toString();
             method.releaseConnection();
             return strEncoding;
           }
           strBuffer = new StringBuffer();
           pos = JQueryBase.getTagText(strHtml, "<meta", ">", strBuffer, false, pos);
         }
         strEncoding = getFileEncoding(strUrl, timeout);
         if (strEncoding == null)
           strEncoding = "GBK";
       }
       method.releaseConnection();
     } catch (Exception e) {
       System.out.println(e.getClass() + "对" + strUrl + "提取网页编码信息出错");
       return null;
     }
     return strEncoding;
    }
    protected static String getContentCharSet(Header contentheader) {
     String charset = null;
        if (contentheader != null) {
            HeaderElement values[] = contentheader.getElements();
            if (values.length == 1) {
             NameValuePair param = values[0].getParameterByName("charset");
                if (param != null) {
                charset = param.getValue();
                }
            }
         }
         return charset;
     }
}