如何在客户端jsp上显示报告? [英] How to display the reports on client side jsp?

查看:237
本文介绍了如何在客户端jsp上显示报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在jsp页面中显示结果。在我的In dex.html中有一个链接,
< a href =vehicleReport.jsp>车辆报告< / a>

I am trying to display the result in jsp page. In my In dex.html has a link as , <a href="vehicleReport.jsp">Vehicle Report</a>

vehicleReport.jsp 我显示报告为,

<body>
 <%
  Connection con=null;
  try{
 con=VehicleDetails.getConnection();
 InputStream inputStream = new FileInputStream ("E:/ReportFld/report4.jrxml");

Map parameters = new HashMap();

JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
@SuppressWarnings("unchecked")
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, con);
out.clear(); // where out is a JspWriter
out = pageContext.pushBody();
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
}
catch(Exception e){e.printStackTrace();}
finally{
con.close();
}

%>
</body>

但问题是报告不可见。在jsp中它显示一些不可读的文本。我收到错误信息,

But problem is report is not visible. In jsp it displays some unreadable text. and I am getting error message as,

SEVERE: Servlet.service() for servlet [jsp] in context with path [/Reports] threw exception [java.lang.IllegalStateException: getOutputStream() has already been called for this response] with root cause
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:636)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:213)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)

如何解决这个问题?

推荐答案

尝试使用

JasperExportManager.exportReportToPdfFile(JasperPrint jsperPring, String fileName);

而不是

JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());

然后在浏览器或任何你想要的地方显示你的PDF格式。

and then display your pdf in browser or anywhere you want.

这篇关于如何在客户端jsp上显示报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆