62,620
社区成员
发帖
与我相关
我的任务
分享
StringBuffer sb=new StringBuffer("<nprovince>");
for(City city:clist){
sb.append("<scity>").append(city.getCityId()).append("</scity>");
sb.append("<scity>").append(new String(city.getName().getBytes("iso8859-1"),"utf-8")).append("</scity>");
//传递中文名称。
}
sb.append("</nprovince>");
if(req.status == 200){
var city=req.responseXML.getElementsByTagName("scity");
var str=new Array();
var strname=new Array();
for(var i=0;i<city.length;i=i+2){
str[i]=city[i].firstChild.data;
strname[i]=city[i+1].firstChild.data;
alert(unescape(strname[i]));//中文乱码
}
buildSelect(str,strname,document.getElementById("scity"));
}
response.setCharacterEncoding("UTF-8"); // 设置输出编码
response.setContentType("text/xml; charset=UTF-8"); // 通知客户端
PrintWriter out = response.getWriter();
out.println("<?xml version='1.0' encoding='UTF-8'?>");
out.println("<root>中文中文</root>"); // 直接输出汉字
out.flush();
var res = req.responseXML.documentElement.firstChild.nodeValue;
alert(res); // 不会乱码