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>
In vehicleReport.jsp
I am displaying report as,
<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>
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)
How to resolve this?
Try using
instead of
and then display your pdf in browser or anywhere you want.