zoukankan      html  css  js  c++  java
  • 导出报表

    public String export() {
            HttpServletResponse response = ServletActionContext.getResponse();
            filename = filename==null?"chart":filename;
            ServletOutputStream out = null;
            try {
                out = response.getOutputStream();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            if (null != type && null != svg) {
                svg = this.handleSvg(svg);
                String ext = "";
                Transcoder t = null;
                if (type.equals("image/png")) {
                    ext = "png";
                    t = new PNGTranscoder();
                } else if (type.equals("image/jpeg")) {
                    ext = "jpg";
                    t = new JPEGTranscoder();
                } else if (type.equals("application/pdf")) {
                    ext = "pdf";
                    t =(Transcoder) new PDFTranscoder();
                } else if(type.equals("image/svg+xml")) 
                    ext = "svg";   
                response.addHeader("Content-Disposition", "attachment; filename="+ filename + "."+ext);
                response.addHeader("Content-Type", type);
                
                if (null != t) {
                    TranscoderInput input = new TranscoderInput(new StringReader(svg));
                    TranscoderOutput output = new TranscoderOutput(out);
                    try {
                        t.transcode(input, output);
                    } catch (TranscoderException e) {
                        try {
                            out.print("Problem transcoding stream. See the web logs for more details.");
                        } catch (IOException e1) {
                            e1.printStackTrace();
                        }
                        e.printStackTrace();
                    }
                } else if (ext.equals("svg")) {
                    try {
                        OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
                        writer.append(svg);
                        writer.close();
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }catch (IOException e1) {
                        e1.printStackTrace();
                    }
                } else
                    try {
                        out.print("Invalid type: " + type);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
            } else {
                response.addHeader("Content-Type", "text/html");
                try {
                    out.println("Usage:
    	Parameter [svg]: The DOM Element to be converted." +
                            "
    	Parameter [type]: The destination MIME type for the elment to be transcoded.");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {
                out.flush();
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    _____________________________________________________________________________________________________ ***************************************************************************************************************** ===坚持、奋斗***今天的努力只为更好的明天***奋斗、坚持===********************** ==========================================================================================
  • 相关阅读:
    ubuntu12.04下设置IPv6
    ubuntu下vncserver配置
    ubuntu12.04安装gerrit代码审核服务器
    Linux + Eclipse 配置交叉编译环境
    进程间通信基础
    ubuntu下搭建git服务器
    udev
    rpcgen的简单讲解及例子程序
    rpc简介、原理、实例-缘于difx
    windows下常用开源软件
  • 原文地址:https://www.cnblogs.com/mlloc-clove/p/3978731.html
Copyright © 2011-2022 走看看