2012-03-21 3 views
1

サーバーサイド(Tomcat + gwt)でJasperReportを作成する必要があります。 私はハロー世界ジャスパーレポートサーバー側の保存

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の2番目のパラメータで指定する必要があります。

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のパスはどのようにする必要がありますか? –

+0

サーバー側の絶対パスまたは相対パス。 – bugske