我正在尝试在jsp页面中显示结果。在我的In 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)
如何解决这个问题?
答案 0 :(得分:1)
尝试使用
JasperExportManager.exportReportToPdfFile(JasperPrint jsperPring, String fileName);
而不是
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
然后在浏览器或任何您想要的地方显示您的PDF格式。