JSP对URL链接中的中文乱码处理方法
时间:2021-04-08 13:36:21
收藏:0
阅读:0
场景:在 jsp 页面中获取到 input 框的中文值,作为参数通过 ajax 传递到后端会出现乱码现象
解决方法:
在 jsp 页面中使用 JavaScript 的 encodeURI() 函数对中文参数进行编码:
var chinaName = jQuery("#chinaName ").val();// 获取到中文值 chinaName = encodeURI(encodeURI(chinaName ));// 对该中文值进行两次编码
在后端程序中使用 URLDecoder.decode(string,"UTF-8"); 对该中文参数进行解码:
chinaName = URLDecoder.decode(chinaName,"UTF-8");// 对中文参数进行解码
评论(0)