var chart = new FusionCharts("${ctx}/plugins/FusionCharts/Charts/Column3D.swf","ChartId","904","300"); chart.setDataURL("${ctx}/info/getDataInfo");
try { String beginYear = super.getParameter("beginYear"); String endYear = super.getParameter("endYear"); StringBuffer wsdwFileContent = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?><chart caption=\"" + beginYear + "年至" + endYear + "年\" baseFontSize=\"12\" palette=\"2\" bgColor=\"#99CCFF,#FFFFFF\"></chart>"); getResponse().setContentType("application/xml"); getResponse().setCharacterEncoding("utf-8"); byte[] tjkjByte = wsdwFileContent.toString().getBytes("utf-8"); getResponse().getOutputStream().write(tjkjByte); } catch (IOException e) { e.printStackTrace(); }
最终页面怎么也无法生成图表,显示"Invalid XML Data"。
网上查找资料说是在生成XML文档前,必须插入BOM标记(Byte Order Mark),代码如下:
try {
String beginYear = super.getParameter("beginYear");
String endYear = super.getParameter("endYear");
StringBuffer wsdwFileContent = new StringBuffer(getBom() + "<?xml version=\"1.0\" encoding=\"UTF-8\"?><chart caption=\"" + beginYear + "年至" + endYear + "年\" baseFontSize=\"12\" palette=\"2\" bgColor=\"#99CCFF,#FFFFFF\"></chart>");
getResponse().setContentType("application/xml");
getResponse().setCharacterEncoding("utf-8");
byte[] tjkjByte = wsdwFileContent.toString().getBytes("utf-8");
getResponse().getOutputStream().write(tjkjByte);
} catch (IOException e) {
e.printStackTrace();
}
getBom() 方法:
public String getBom () { String bom = null; try { byte[] bomByte = new byte[]{ (byte) 0xef,(byte) 0xbb,(byte) 0xbf }; bom = new String(bomByte,"UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return bom; }原文链接:/xml/299996.html