版权声明:本文为博主原创文章,未经博主允许不得转载! https://blog.csdn.net/bojinyanfeng/article/details/84999633
window.location.href传参带中文到java后台是乱码的问题解决方法
方法一:使用单个encodeURI()对中文进行编码处理。
(1).页面中先对中文进行编码。
window.location.href = url+"&name=" + encodeURI("中文") ;
(2).在服务端进行解码。
String name = new String(request.getParameter("name").getBytes("ISO8859-1"), "UTF-8");
方法二:使用双重encodeURI()对中文进行编码处理。
(1).页面中先对中文进行编码。
window.location.href = url+"&name=" + encodeURI(encodeURI("中文")) ;
(2).在服务端进行解码。
String name = java.net.URLDecoder.decode(request.getParameter("name"), "UTF-8");