加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

FusionCharts 动态生成XML数据问题

发布时间:2020-12-16 05:21:36 所属栏目:百科 来源:网络整理
导读:前台页面: 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 endY

前台页面:

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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读