2012-03-21 51 views
1

我必須在服務器端(Tomcat + gwt)上創建一個JasperReport。 我嘗試運行一個hello世界Jasper-Report服務器端保存

public class AuthorReport { 
public static void generate() { 
try { 
    String reportSource = "resources/authorReport.jasper"; 

    JasperReport jasperReport = JasperCompileManager 
    .compileReport(reportSource); 

    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, 
    new HashMap(), new JREmptyDataSource()); 

    JasperExportManager.exportReportToHtmlFile(jasperPrint, "hello_report.html"); 


} catch (Exception e) { 
    e.printStackTrace(); 
} 
} 
} 

我沒有得到任何異常,但我不能明白哪裏是生成的文件,它是否在所有生成的。

也許我必須以某種方式集成Tomcat和JasperReports?

回答

1

您必須在JasperFillManager.fillReport的第二個參數中指定此位置。

public class AuthorReport { 

    public static void generate() { 
     try { 
      String reportSource = "resources/authorReport.jasper"; 

      JasperReport jasperReport = JasperCompileManager.compileReport(reportSource); 

      Map<String, Object> params = new HashMap<String, Object>(); 
      params.put(JRParameter.REPORT_FILE_RESOLVER, new SimpleFileResolver(new File(youPath))); 

      JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource()); 

      JasperExportManager.exportReportToHtmlFile(jasperPrint, "hello_report.html"); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 

祝你好運!

+0

SimpleFileResolver中應該是什麼路徑? – 2012-03-21 12:00:22

+0

服務器端的絕對路徑或相對路徑。 – bugske 2012-03-21 14:33:13