六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 27|回复: 0

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

[复制链接]

升级  10.35%

391

主题

391

主题

391

主题

探花

Rank: 6Rank: 6

积分
1207
 楼主| 发表于 2013-2-7 14:50:30 | 显示全部楼层 |阅读模式
  刚在群里解答了一个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();
????????}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表