逆风的香1314 发表于 2013-2-7 14:50:30

struts的action直接输出中文备注【原创】

  刚在群里解答了一个ajax取action产生的中文页面得到乱码的问题,感觉有必要记下来,这段代码是这么写的,输出编码为utf-8
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee;">????????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();
????????}
页: [1]
查看完整版本: struts的action直接输出中文备注【原创】