前臺:
encodeURIComponent(encodeURIComponent("編碼內容"))
後臺編碼、解碼:
public static String bianma(String str) { // remove null string // 編碼 try { str = URLEncoder.encode(str, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return str; } public static String bianma(String str, String enc) { // remove null string // 編碼 try { str = URLEncoder.encode(str, enc); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return str; } public static String jiema(String str, String enc) { // remove null string // 解碼 try { str = URLDecoder.decode(str, enc); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return str; }