jquery post乱符号問題utf-8 gbk

675 ワード

$を使うとpostがデータをコミットと、jqueryはutf-8を強制的に符号化する.バックグラウンドは他のコードを使うと文字化けして表示されます.フロントでutf-8符号化を用いる、バックグラウンドにデータベースを含むgbkを用いるアプリケーションがある.私たちはactionで符号化変換を行うことができます.具体的には、public static String setCharSet(String str,String oCharSet,String nCharSet){
        try {  
            String tempStrUtf8= new String(str.getBytes(), oCharSet);  
            str=new String( tempStrUtf8.getBytes(nCharSet),nCharSet);  
        } catch (UnsupportedEncodingException e) {  
            log.error(str+"    :"+oCharSet+"   :"+nCharSet+"  ");  
              
        }  
        return str;  
    }