惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Security Blog
Microsoft Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
About on SuperTechFans
月光博客
月光博客
Jina AI
Jina AI
F
Fortinet All Blogs
博客园 - 聂微东
The Cloudflare Blog
美团技术团队
B
Blog RSS Feed
N
Netflix TechBlog - Medium
罗磊的独立博客
The GitHub Blog
The GitHub Blog
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Apple Machine Learning Research
Apple Machine Learning Research
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
博客园 - 三生石上(FineUI控件)
宝玉的分享
宝玉的分享
阮一峰的网络日志
阮一峰的网络日志
V
V2EX

博客园 - cyberghost

Padavan 路由器配置 Cloudflare DDNS Linux关闭占用特定端口的进程 Jackson反序列化泛型List Oracle SQL Developer更改DATE日期的显示格式 解决Navicat导入psc备份文件数据为空 Maven配置环境变量 org.hibernate.LazyInitializationException: could not initialize proxy - no Session Maven项目导出jar包 Eclipse配置Go语言开发环境(GoEclipse) Maven项目设置JDK版本 PowerDesigner16下载和破解 Ubuntu安装JDK配置环境变量 Ubuntu添加eclipse快捷方式 JDK配置环境变量 springMVC获得HttpServletRequest对象 Struts Action返回xml 使用FusionCharts Free显示图表(JSP) Ajax实现表单验证 Java判断指定日期是星期几
FusionCharts Free解决setDataURL中文乱码
cyberghost · 2013-09-06 · via 博客园 - cyberghost

最近在用FusionCharts Free做一个图表的项目,在是用setDataURL时遇到了中文乱码。

编码什么的都设置了UTF-8,可就是不显示,郁闷啊

然后再看官方UTF-8示例的时候发现动态生成的XML需要加上UTF-8 Bom,

示例在\FusionChartsFree\Code\JSP\UTF8Example\目录下。

于是乎。。。

 1 Document doc = DocumentHelper.createDocument();
 2 Element root = doc.addElement("graph");
 3 root.addAttribute("showNames", "1");
 4 root.addAttribute("decimalPrecision", "0");
 5 Element set = root.addElement("set");
 6 set.addAttribute("name", "电梯");
 7 set.addAttribute("value", "134");
 8 Element set1 = root.addElement("set");
 9 set1.addAttribute("name", "空调");
10 set1.addAttribute("value", "122");
11 HttpServletResponse response = ServletActionContext.getResponse();
12 PrintWriter out = response.getWriter();
13 response.setContentType("text/xml;charset=UTF-8");
14 System.out.println(doc.asXML());
15 //utf-8标识
16 byte[] utf8Bom =  new byte[]{(byte) 0xef, (byte) 0xbb, (byte) 0xbf};
17 String utf8BomStr = new String(utf8Bom, "UTF-8");
18 //在xml前加上utf-8标识
19 String xml = utf8BomStr + doc.asXML();
20 out.write(xml);

终于不乱吗了,哇哈哈。。