我必须在服务器端(Tomcat + gwt)上创建一个JasperReport。 我尝试运行一个hello-world
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?
答案 0 :(得分: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();
}
}
}
祝你好运!