有关Ajax 中文乱码问题

1.前台传值乱码

 

   前台JavaScript转码:

   

... 
var url = "reg?userid=" + str;  
url = encodeURI(url);  
url = encodeURI(url);  
... 

 

   后台解码:

 

... 
String userId = request.getParameter("userid");  
userId = java.net.URLDecoder.decode(id,"UTF-8");  
...

 

    前台2次转码,后台一次

 

2.后台传值乱码

 

...  
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
...

 

    转码必须放在前面

你可能感兴趣的:(JavaScript,java,.net,Ajax)