我必须在服务器端 (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?
最佳答案
您必须在 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();
}
}
}
祝你好运!
关于java - Jasper-Report服务器端保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9803311/