Ajax字符编码的问题请这里的高人指点一下

来源:百度知道 编辑:UC知道 时间:2024/05/07 09:20:22
Eclipse3.2(编码为gb2312)+Tomcat环境下Ajax中从服务端以xml的格式返回一段中文res=<response><notice>中文编码测试</notice></response>

PrintWriter out = response.getWriter();
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Type", "text/xml;");
System.out.println(res);
out.close();

客户端编码为gb2312 为什么在alert(xmlHttp.responseXML.getElementsByTagName("notice"));时全是??组成的乱码 请问高手怎么解决这个问题,如果要设置header 能不能麻烦把详细的代码实现写出来 多谢多谢 小弟先谢过了
RE:请问一下,如果需要返回的内容是从DB读出来的呢?如果不用复制粘贴的方法怎么实现呢?servlet那面需要怎么改动呢?谢谢

RE:已经好啦 没想到字符集的不统一问题 问您最后一个问题:在js中难道一定用UTF-8编码么? 另外,多谢您的提示

首先head中加入<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<br>
<br>代码如下
<br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
<br><html xmlns="<a href="http://www.w3.org/1999/xhtml" target="_blank">http://www.w3.org/1999/xhtml</a>">
<br><hea