导出报表
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:\n\tParameter [svg]: The DOM Element to be converted." + "\n\tParameter [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; }
_____________________________________________________________________________________________________
*****************************************************************************************************************
===坚持、奋斗***今天的努力只为更好的明天***奋斗、坚持===**********************
==========================================================================================