其他分享
首页 > 其他分享> > JSP对URL链接中的中文乱码处理方法

JSP对URL链接中的中文乱码处理方法

作者:互联网

场景:在 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");// 对中文参数进行解码

  

标签:chinaName,中文,URL,乱码,JSP,参数,encodeURI,decode
来源: https://www.cnblogs.com/jiangaihu/p/14629023.html