刚在群里解答了一个ajax取action产生的中文页面得到乱码的问题,感觉有必要记下来,这段代码是这么写的,输出编码为utf-8
response.setContentType("text/html;charset=utf-8");
response.setHeader("Cache-Control", "no-cache");
try
{
PrintWriter pw=new PrintWriter(new OutputStreamWriter(response.getOutputStream(),"utf-8"));
pw.write(xmlBuf.toString());
pw.close();
}
catch(java.io.IOException e)
{
e.printStackTrace();
}
放这里,以后有用。
response.setHeader("Cache-Control", "no-cache");
try
{
PrintWriter pw=new PrintWriter(new OutputStreamWriter(response.getOutputStream(),"utf-8"));
pw.write(xmlBuf.toString());
pw.close();
}
catch(java.io.IOException e)
{
e.printStackTrace();
}