//前台中文传递(encodeURI要编码两次)
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <button id="a" onclick="shiborikomuFw()">测试</button> </body> <script type="text/javascript"> function shiborikomuFw() { var a="我的"; alert(a); alert(encodeURI(a)); alert(encodeURI(encodeURI(a))); //window.location.href = "http://127.0.0.1:8080/kabao-api/xtetest/c.do?title="+encodeURI(encodeURI(a)); //上面的方式和下面的方式都可以 window.location.href=encodeURI(encodeURI("http://127.0.0.1:8080/kabao-api/xtetest/c.do?title="+a)); } </script> </html>
后台接收之后的代码操作
System.out.println(title); //%E6%88%91%E7%9A%84 String encode = URLDecoder.decode(title, "UTF-8"); System.out.println(encode); //我的
时间: 2024-10-06 12:46:50