jsp页面间传递参数 中文乱码问题
window.location="Test.jsp?param1="+encodeURI(encodeURI(str));//对中文参数进行双层编码后再传递
URLDecoder.decode(request.getParameter("param1"),"utf-8");//对中文参数进行解码
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
url="xxx.jsp?id="+java.net.URLEncoder.encode("中文", "UTF-8") //加码
接收时,我们用
String inf=request.getParameter("id");
inf= new String(inf.getBytes("iso-8859-1"),"UTF-8"); 解码
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var title = document.getElementById("title");
var url = "xxx.jsp?title="+encodeURI(title.value);//加码
String title = new String(request.getParameter("qTitle").getBytes("iso-8859-1"),"UTF-8");解码
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ajax传递中文乱码
解决get请求乱码
$.ajax({
url: "" ,
type: "GET",
data: { pwd: encodeURI('周'), username: 'tl' },
success: function(data) {
alert(data.ok);
},
error: function(a, b, c) {
alert("error==" + b);
}
});