分类: Java
2009-09-02 14:19:50
1.把相关的java ,jsp,js 文件编码方式都改成utf-8
2.
response.setContentType("text/json;charset=utf-8");
response.setHeader("text/json", message);
response.setHeader("Cache-Control", "no-cache");
3.使用如下代码对你的request,response进行测试,看看到底是什么编码
System.out.println(response.getCharacterEncoding()+"###");
System.out.println(request.getCharacterEncoding()+"####");
如果输出都为utf-8就解决了。
一个完整的处理方法如下:
private void print(JSONObject message) {
HttpServletResponse response = ServletActionContext.getResponse();
HttpServletRequest request = ServletActionContext.getRequest();
response.setHeader("X-JSON", message.toString());
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache");
PrintWriter print = null;
try {
print = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
print.print(message.toString());
print.flush();
}