url上的中文字符是ISO-8859-1。后台獲取中文亂碼解決問題。


url上的中文字符是ISO-8859-1。后台獲取中文亂碼解決問題。

需要轉碼

public static String changeCharset(String str, String defaultValue)
    {
        if (str != null)
        {
            
            try
            {
                if ((StringUtils.isNotBlank(str)) && str.equals(
                        new String(str.getBytes("ISO-8859-1"), "ISO-8859-1")))
                {
                    return new String(str.getBytes("ISO-8859-1"), "UTF-8");
                }
                return str;
            }
            catch (UnsupportedEncodingException e)
            {
                throw new RuntimeException("字符串轉換異常!!!!");
                
            }
        }
        return defaultValue;
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM