前端編碼,後臺解碼

前臺:

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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章