URLEncoder、URLDecoder
public static void main(String[] args) { String a = "欢迎你"; try { //编码(后端传给前端数据之前要先 URLEncoder) String b = URLEncoder.encode(a, "UTF-8"); System.out.println(b); //解码(前端传给后端数据,后端接收后要先 URLDecoder) String c= URLDecoder.decode(b, "UTF-8"); System.out.println(c); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }