2010-10-15 10 views
0

J'utilise iReport pour créer le fichier JRXML. Pour exporter ces données en utilisant Java Struts, j'utilise le code suivant.Exportation de graphiques iReport au format HTML

public ActionForward reportExport(ActionMapping mapping, ActionForm form, 
    HttpServletRequest req, HttpServletResponse res) throws Exception { 
    String reportType2=req.getParameter("reporttype"); 
    System.out.println("reportType2"+reportType2); 
    String filename = "slademofinalreport1.jrxml"; 
    /*String reporttype = "pdf";*/ 
    String reporttype = reportType2; 
    System.out.println(filename); 
    System.out.println(reporttype); 

    Class.forName("com.mysql.jdbc.Driver"); 
    Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/epim","", ""); 
    String query="select projectname,processname,queuename,sladuedate,d.createddate,d.lastupdatedate,count(d.documentid)as numofdocuments,datediff(d.createddate,d.lastupdatedate)/count(d.documentid) as averagesla,datediff(d.sladuedate,d.createddate) as sladefined from epim.mstqueue mq,epim.userproject u,epim.documentqueuedetails d,epim.mstproject mproj,epim.mstprocess mproc where d.projectid=u.projectid and u.userid=13 and mproj.projectid=d.projectid and mproc.processid=d.processid and mq.queueid=d.queueid group by queuename "; 

    PreparedStatement stmt1=con.prepareStatement(query); 
    //stmt1.setInt(1,200); 
    java.sql.ResultSet rs3=stmt1.executeQuery(); 
    /*Statement stmt1=(Statement) con.createStatement(); 
    java.sql.ResultSet rs3= stmt1.executeQuery("select projectname,processname,queuename,sladuedate,d.createddate,d.lastupdatedate,count(d.documentid)as numofdocuments,datediff(d.createddate,d.lastupdatedate)/count(d.documentid) as averagesla,datediff(d.sladuedate,d.createddate) as sladefined from epim.mstqueue mq,epim.userproject u,epim.documentqueuedetails d,epim.mstproject mproj,epim.mstprocess mproc where d.projectid=u.projectid and u.userid=13 and mproj.projectid=d.projectid and mproc.processid=d.processid and mq.queueid=d.queueid group by queuename");*/ 
    JRResultSetDataSource obj=new JRResultSetDataSource(rs3); 

// String path = application.getRealPath("/"); 
    JasperReport jasperReport = JasperCompileManager.compileReport("D:/subash/kmsnewwork/KMS_SUBASH/WebContent/jasperreport/"+ filename); 
    System.out.println("Report Compiled..."); 
    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null,obj); 
    System.out.println("Report Created..."); 
    ServletOutputStream ouputStream = res.getOutputStream(); 
    JRExporter exporter = null; 

    if("pdf".equalsIgnoreCase(reporttype)) 
    { 
    res.setContentType("application/pdf"); 
    res.setHeader("Content-Disposition", "inline; filename=\"file.pdf\""); 

    exporter = new JRPdfExporter(); 
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream); 
    } 
    else if("rtf".equalsIgnoreCase(reporttype)) 
    { 
    res.setContentType("application/rtf"); 
    res.setHeader("Content-Disposition", "inline; filename=\"file.rtf\""); 

    exporter = new JRRtfExporter(); 
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream); 
    } 
    else if("html".equalsIgnoreCase(reporttype)) 
    { 
    exporter = new JRHtmlExporter(); 
    exporter.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM,false); 
    exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, new Boolean(false)); 

    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream); 
    } 
    else if("xls".equalsIgnoreCase(reporttype)) 
    { 
    res.setContentType("application/xls"); 
    res.setHeader("Content-Disposition", "attachment; filename=\"file.xls\""); 

    exporter = new JRXlsExporter(); 
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream); 
    } 
    else if("csv".equalsIgnoreCase(reporttype)) 
    { 
    res.setContentType("application/csv"); 
    res.setHeader("Content-Disposition", "inline; filename=\"file.csv\""); 

    exporter = new JRCsvExporter(); 
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream); 
    } 

    try 
    { 
    exporter.exportReport(); 
    } 
    catch (JRException e) 
    { 
    throw new ServletException(e); 
    } 
    finally 
    { 
    if (ouputStream != null) 
    { 
    try 
    { 
    ouputStream.close(); 
    } 
    catch (IOException ex) 
    { 
    System.out.println("exception thrown"); 
    } 
    } 
    } 
    /*return mapping.findForward("goLoginPage");*/ 
    return mapping.findForward("goReportFilterPage"); 
} 

Tout le format d'exportation obtient le graphique sauf le code HTML. Quelqu'un peut-il m'aider? Dois-je faire quelque chose de plus pour HTML parce que le tableau ne s'affiche pas au format HTML?

Répondre

1

Contrairement aux autres formats de fichiers, les images ne sont pas intégrées dans le fichier html. Un soin particulier est donc nécessaire.

Voir JRHtmlExporterParameter:..

« Une question importante est des images Les magasins de format HTML des images sous forme de fichiers séparés, l'exportateur doit savoir où ces images seront stockées si elles sont stockées sur le disque, le paramètre IMAGES_URI sera initialisé avec une chaîne contenant le nom du fichier sur le disque.Si ils restent en mémoire, IMAGES_URI doit pointer vers une ressource capable d'envoyer les images au navigateur (comme une servlet d'image, comme indiqué dans l'exemple webapp). "