Ajax中文问题

进一步-海阔天空 2006-06-26 01:29:55
我通过这样的代码向客户端返回XML。
response.setContentType("text/xml");
PrintWriter out = new PrintWriter(response.getOutputStream());
System.out.println(xmlutil.transformDOM(doc));
out.println(xmlutil.transformDOM(doc));
out.close();
在控制台打出中文是对的。
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<RESPONSE>
<IMAGE>
<ENVELOPE minx="51273.9079795552" miny="45059.4999503881" maxx="52106.0918876012" maxy="45559.4999503881"/>
<OUTPUT file="D:\Tomcat 5.0\webapps\suzhou\output\test2_MENGLIKUN744150088.jpg" url="http://menglikun:8181/suzhou/output/test2_MENGLIKUN744150088.jpg"/>
</IMAGE>
<HOTSPOT x="51689.9999335782" y="45309.4999503881" layer="SUZHOU.MENPAIPOINT" objectid="1841" objname="半边街8号">半边街8号</HOTSPOT></RESPONSE>
</ARCXML>

但在客户端用
alert(xmlHttp.responseText);
弹出了这样的结果,跟服务器端明显不一致,是什么原因呢?如何解决?

<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<RESPONSE>
<IMAGE>
<ENVELOPE minx="51273.9079795552" miny="45059.4999503881" maxx="52106.0918876012" maxy="45559.4999503881"/>
<OUTPUT file="D:\Tomcat 5.0\webapps\suzhou\output\test2_MENGLIKUN744150088.jpg" url="http://menglikun:8181/suzhou/output/test2_MENGLIKUN744150088.jpg"/>
</IMAGE>
<HOTSPOT x="51689.9999335782" y="45309.4999503881" layer="SUZHOU.MENPAIPOINT" objectid="1841" objname=">/HOTSPOT></RESPONSE>
</ARCXML>
...全文
162 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
huaguol 2006-07-29
  • 打赏
  • 举报
回复
在java类里加:
response.setContentType("text/xml;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
jackson416 2006-07-29
  • 打赏
  • 举报
回复
统一编码...

是XML文件的用xmlHttp.responseXML.xml
o光o 2006-07-29
  • 打赏
  • 举报
回复
private void setHead(HttpServletRequest request,HttpServletResponse response) throws Exception{
response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
request.setCharacterEncoding("UTF-8");
response.setContentType("text/xml;charset=UTF-8");
response.getWriter().println("<?xml version='1.0' encoding='UTF-8'?>");
}
o光o 2006-07-29
  • 打赏
  • 举报
回复
private void setHead(HttpServletRequest request,HttpServletResponse response) throws Exception{
response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
request.setCharacterEncoding("GBK");
response.setContentType("text/xml;charset=GBK");
response.getWriter().println("<?xml version='1.0' encoding='GBK'?>");
}
Ryo_Hazuki 2006-06-26
  • 打赏
  • 举报
回复
prototype.js
  • 打赏
  • 举报
回复
改了一下编码alert(xmlHttp.responseText)显示是对的,但xmlHttp.responseXML还是不对,为什么?
njtucomputer 2006-06-26
  • 打赏
  • 举报
回复
关键是你服务器端的编码 是否和 客户端一致

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧