Dynamic 动态Jasper报告:report.toPdf(OutputStream)在JSF2中不工作
我正在JSF2.2项目中使用动态JasperReports5.0.1。代码在JSF1.2中运行良好,但在JSF2.2中没有将报告呈现到输出流。我不确定这是框架的升级版,或者我做错了什么。以下两行代码运行良好:-Dynamic 动态Jasper报告:report.toPdf(OutputStream)在JSF2中不工作,dynamic,jasper-reports,jsf-2.2,Dynamic,Jasper Reports,Jsf 2.2,我正在JSF2.2项目中使用动态JasperReports5.0.1。代码在JSF1.2中运行良好,但在JSF2.2中没有将报告呈现到输出流。我不确定这是框架的升级版,或者我做错了什么。以下两行代码运行良好:- report.show() opens the reports in Jasper Viewer and report.toPdf(new FileOutputStream("c:/report.pdf")) writes the report to c drive 但是,以下代
report.show() opens the reports in Jasper Viewer
and report.toPdf(new FileOutputStream("c:/report.pdf")) writes the report to c drive
但是,以下代码在没有任何错误日志的情况下什么也不做:-
//.................................Report Printing Starts...................
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse resp = (HttpServletResponse)facesContext.getExternalContext().getResponse();
facesContext.responseComplete();
JasperReportBuilder report = DynamicReports.report();//a new report
resp.setHeader("Content-disposition", "attachment;");
ServletOutputStream out = resp.getOutputStream();
try
{
report
.setColumnTitleStyle(columnTitleStyle)
.ignorePageWidth()
.highlightDetailEvenRows()
.columns(Col_Array) //where Col_Array is defined as TextColumnBuilder[] Col_Array; and the elements in it display correctly
.title(cmp.text("Offrs Panel").setStyle(boldCenteredStyle))
.pageFooter(cmp.pageXofY().setStyle(boldCenteredStyle))
.setDataSource(createReportDataSource()) // createReportDataSource return a JRDataSource and its valid as it opens in Jasper viewer correctly
//.show() this code works
.toPdf(out) //.............this is problem statement. I want to open a pdf file here in native program like adobe and NOT in jasper viewer (
//.toExcelApiXls(out) showing same behavior and not opening the excel file
//.toPdf(new FileOutputStream("c:/report.pdf")); this code works too
}
catch (Exception e)
{
e.printStackTrace();
}
out.flush();
out.close();
//.................................Report Printing Ends...................
请纠正其他要求。可能是
附件代码>是否没有足够的信息供浏览器使用?相反,可以添加以pdf结尾的文件名,例如附件;filename=download.pdf
(请参阅更多)。我尝试了。但是没有运气。它会在Jasper Viewer中持续打开,而Excel文件根本不会打开。碰撞,所以没有碰撞。为了正确理解这一点,您需要在浏览器中请求下载,结果将打开Jasper Viewer并显示PDF?其他文件呢?对于您的另一个问题:APItoExcelApiXls
已弃用,您应该使用toXls
。好的。不会再碰了。关于这个问题,toPdf是否进行了去润滑?我的问题是…当我使用toPdf时,报告会在jasper查看器中打开,而toExcelApiXls/toXls都不做任何事情。再详细不过了。仍然不清楚工作流和基础架构是如何运作的。请回答以下问题:您的服务器在哪里?与客户端在同一台机器上?可能是附件代码>是否没有足够的信息供浏览器使用?相反,可以添加以pdf结尾的文件名,例如附件;filename=download.pdf
(请参阅更多)。我尝试了。但是没有运气。它会在Jasper Viewer中持续打开,而Excel文件根本不会打开。碰撞,所以没有碰撞。为了正确理解这一点,您需要在浏览器中请求下载,结果将打开Jasper Viewer并显示PDF?其他文件呢?对于您的另一个问题:APItoExcelApiXls
已弃用,您应该使用toXls
。好的。不会再碰了。关于这个问题,toPdf是否进行了去润滑?我的问题是…当我使用toPdf时,报告会在jasper查看器中打开,而toExcelApiXls/toXls都不做任何事情。再详细不过了。仍然不清楚工作流和基础架构是如何运作的。请回答以下问题:您的服务器在哪里?与客户端在同一台计算机上?