å¨å¤ççæµç¨ä¸ï¼å¨æ¥æ¶å°å®¢æ·ä¼ æ¥çæ¥æçæ¶åè¿è¡ç¼ç 转æ¢ãå ä¸ä¸é¢ä¸¤ä¸ªæ¹æ³ï¼å¨å¾å°å®¢æ·è¯·æ±æ¥ææ¶åªéè°ç¨ç¬¬ä¸ä¸ªæ¹æ³è½¬æ¢ä¸ä¸å³å¯ã
//ä¸æå符å¤ç
public String charSetConvert(String xmlRequest){
String charSet = NeopServerImpl.getEncoding(xmlRequest);
try {
byte[] b = xmlRequest.getBytes(charSet);
xmlRequest = new String(b, "UTF-8");
} catch (Exception e) {
logger.error("è¾å
¥çå
容ä¸å±äºå¸¸è§çç¼ç æ ¼å¼,请åä»ç»æ ¸å®", e);
}
return xmlRequest;
}
public static String getEncoding(String str) {
String encode = "GB2312";
try {
if (str.equals(new String(str.getBytes(encode), encode))) { // å¤ææ¯ä¸æ¯GB2312
String s = encode;
return s; // æ¯çè¯ï¼è¿åGB2312ï¼ä»¥ä¸ä»£ç åç
}
} catch (Exception e) {
logger.error("getEncodingå¼å¸¸---GB2312", e);
}
encode = "ISO-8859-1";
try {
if (str.equals(new String(str.getBytes(encode), encode))) { // å¤ææ¯ä¸æ¯ISO-8859-1
String s1 = encode;
return s1;
}
} catch (Exception e) {
logger.error("getEncodingå¼å¸¸---ISO-8859-1", e);
}
encode = "UTF-8";
try {
if (str.equals(new String(str.getBytes(encode), encode))) { // å¤ææ¯ä¸æ¯UTF-8ç¼ç
String s2 = encode;
return s2;
}
} catch (Exception e) {
logger.error("getEncodingå¼å¸¸---UTF-8", e);
}
encode = "GBK";
try {
if (str.equals(new String(str.getBytes(encode), encode))) { // å¤ææ¯ä¸æ¯GBK
String s3 = encode;
return s3;
}
} catch (Exception e) {
logger.error("getEncodingå¼å¸¸---GBK", e);
}
return ""; // å°è¿ä¸æ¥ï¼ä½ å°±åºè¯¥æ£æ¥æ¯ä¸æ¯å
¶ä»ç¼ç å¦
}
温馨提示:内容为网友见解,仅供参考