I am creating a pdf using jasper report and I need to pass this pdf from servlet.Can, someone will help me where I made a mistake. This is a piece of code that I use in my application.
ServletOutputStream servletOutputStream = response.getOutputStream();
String fileName="test.pdf";
response.setContentType("application/pdf");
response.setHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");
response.setHeader("Cache-Control", "no-cache");
try
{
Map parameters = new HashMap();
parameters.put("SUBREPORT_DIR", JasperReportFilepath);
parameters.put("TestId", testID);
JasperPrint jprint=JasperFillManager.fillReport(filePath, parameters, conn);
byte[] output=JasperExportManager.exportReportToPdf(jprint);
System.out.println("Size====>"+output.length);
servletOutputStream.write(output);
servletOutputStream.flush();
servletOutputStream.close();
System.out.println("===============>Streaming perfectly");
}
catch(Exception e)
{
System.out.println("===============>+JasperException"+e.getMessage());
}
and I also could not get the error message. Everything is working fine, but the document is not working. Please help me deal with the problem.
source
share