日期:2014-05-16  浏览次数:20712 次

jquery-ajax从后台返回值为中文时乱码解决方法
前提是该项目前台jsp编码为gbk,过滤器也设置为gbk
  <filter>
    <filter-name>SetCharacterEncodingFilter</filter-name>
    <filter-class>eoffice.servlet.SetCharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>GBK</param-value>
    </init-param>
  </filter>


后台java为
	    	、
   JSONArray  resultList=JSONArray.fromObject(innerArticleColumnList);
	    	response.setContentType("text/json;charset=GBK");   
	    	response.setHeader("Cache-Control", "no-cache");   
		out.print(resultList.toString());

怎么滴也差不错到底哪步错了,后来网上终于找到答案,
     out=response.getWriter(); //输出中文,这一句一定要放到response.setContentType("text/xml;charset=utf-8"),  response.setHeader("Cache-Control", "no-cache")后面,否则中文返回到页面是乱码 

非常感谢这位大大。http://penghuaiyi.iteye.com/blog/470325