Java 部署JasperReport时+;web项目到Tomcat7,它无法显示导出的Html
我可以在MyEclipse Tomcat中正确运行该项目,您可以从image1中看到它 饼图: 但后来我将.war文件保存到Tomcat,我什么也没有得到,如图2所示 [失败的节目][2] 下面是我关于exort的代码Java 部署JasperReport时+;web项目到Tomcat7,它无法显示导出的Html,java,linux,tomcat,jasper-reports,Java,Linux,Tomcat,Jasper Reports,我可以在MyEclipse Tomcat中正确运行该项目,您可以从image1中看到它 饼图: 但后来我将.war文件保存到Tomcat,我什么也没有得到,如图2所示 [失败的节目][2] 下面是我关于exort的代码 File reportFile = new File(this.getServletConfig().getServletContext().getRealPath("/report2.jasper")); List<SatisfPieData> satisfPie
File reportFile = new File(this.getServletConfig().getServletContext().getRealPath("/report2.jasper"));
List<SatisfPieData> satisfPieDataList = satifyDao.querySatisfPieData(sql);
JRDataSource dataSource = new JRBeanCollectionDataSource(satisfPieDataList);
Map<String, Object> parameters = new HashMap<String, Object>();
try
{
PrintWriter out = response.getWriter();
try
{
//response.setContentType("text/html;charset=UTF-8");
response.setContentType("text/html");
JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile(reportFile.getPath());
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,dataSource);
HtmlExporter exporter = new HtmlExporter();
request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
SimpleHtmlExporterOutput output = new SimpleHtmlExporterOutput(out);
output.setImageHandler(new WebHtmlResourceHandler("image?image={0}"));
exporter.setExporterOutput(output);
exporter.exportReport();
}
catch(JRException jre)
{
jre.printStackTrace();
}
finally
{
if(out!= null)
{
try
{
out.close();
}
catch(Exception e)
{
}
}
}
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
好像有个错误,但我没听懂。函数似乎没有结束或正在被赋予
jasperPrint功能似乎并未结束:
有人知道错误的原因吗?我将不胜感激 你的问题不清楚。应用程序是否冻结了此方法(JasperFillManager.fillReport)?是的,诸如“JRBeanCollectionDataSource”、“JRLoader.loadObjectFromFile”等函数可以成功运行。但该方法(JasperFillManager.fillReport)似乎已冻结。不管我等了多久,程序都无法运行下一个代码“System.out.println”(“jasperPrint end”)”。顺便说一下,数据源只有3行。整个项目可以在内部MyEclipse Tomcat中成功运行,但在外部Tomcat中运行失败。这让我很困惑。谢谢。@Alex K
JasperPrint jasperPrint =JasperFillManager.fillReport(jasperReport,parameters,dataSource)