一尘不染

如何在客户端jsp上显示报告?

jsp

我正在尝试在jsp页面中显示结果。在我的dex.html中,链接为, <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中,它显示一些不可读的文本。我收到错误消息,

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)

如何解决呢?


阅读 236

收藏
2020-06-10

共1个答案

一尘不染

尝试使用

JasperExportManager.exportReportToPdfFile(JasperPrint jsperPring, String fileName);

代替

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

然后在浏览器或所需的任何位置显示pdf。

2020-06-10