public static String toUTF8(String str) { if (isEmpty(str)) { return ""; } try { if (str.equals(new String(str.getBytes("GB2312"), "GB2312"))) { str = new String(str.getBytes("GB2312"), "utf-8"); return str; } } catch (Exception exception) { } try { if (str.equals(new String(str.getBytes("ISO-8859-1"), "ISO-8859-1"))) { str = new String(str.getBytes("ISO-8859-1"), "utf-8"); return str; } } catch (Exception exception1) { } try { if (str.equals(new String(str.getBytes("GBK"), "GBK"))) { str = new String(str.getBytes("GBK"), "utf-8"); return str; } } catch (Exception exception3) { } return str;}public static boolean isEmpty(String str) { if (str != null && !str.trim().isEmpty()) { return false; } return true;}
java获取:
String name = TypeUtil.toUTF8(request.getParameter("name"));