中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

字符串 java字符串編碼轉(zhuǎn)換處理類

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用

該字符串處理類包括將ISO-8859-1編碼的字符串轉(zhuǎn)換成GBK編碼 、對輸入的字符串進(jìn)行一次編碼轉(zhuǎn)換,防止SQL注入和驗(yàn)證URL地址是否存在的方法。

字符串處理類(編碼轉(zhuǎn)化、SQL注入、URL)

import java.net.HttpURLConnection;
import java.net.URL;

public class StringUtils {
    public String toGBK(String strvalue) {
        try {
            if (strvalue == null) { //當(dāng)變量strvalue為null時(shí)
                return "";  //將返回空的字符串
            } else {
                //將字符串轉(zhuǎn)換為GBK編碼
                strvalue = new String(strvalue.getBytes("ISO-8859-1"), "GBK"); 
                return strvalue;    //返回轉(zhuǎn)換后的輸入變量strvalue
            }
        } catch (Exception e) {
            return "";
        }
    }

    // 對輸入的字符串進(jìn)行一次編碼轉(zhuǎn)換,防止SQL注入
    public String StringtoSql(String str) {
        if (str == null) {              //當(dāng)變量str為null時(shí)
            return "";          //返回空的字符串
        } else {
            try {
                                     //將'號(hào)轉(zhuǎn)換化為空格
                str = str.trim().replace('\'', (char) 32);              } catch (Exception e) {
                return "";
            }
        }
        return str;
    }
    //驗(yàn)證URL地址是否存在
    public int isURLExist(String url){
        int rtn=0;
        try {
            URL u = new URL(url);
            HttpURLConnection urlconn = (HttpURLConnection) u.openConnection();
            int state = urlconn.getResponseCode();
            if (state == 200) {     //表示URL地址存在
                //String succ = urlconn.getURL().toString();
                rtn=1;
            } else {                //表示URL地址不存在
                rtn=0;
            }
        } catch (Exception e) {
            rtn=0;
        }
        return rtn;
    }
}

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:C++操作sqlite3數(shù)據(jù)庫示例代碼

下一篇:把數(shù)字轉(zhuǎn)換成人民幣大寫的形式Java類