How to display pdf report in jsp?

0

I have a link in one jsp as,

 

<form action="VehicleReports">
<a href="vehicleReport.jsp">Vehicle Report</a>
</form>
 
I have writen VehicleReports servlet as,
 
 
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 
Connection con=null;
try{
 
response.setContentType("application/pdf"); 
 
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);
 
JasperExportManager.exportReportToPdfFile(jasperPrint, "D:/reports/vehicle2_jasper.pdf");
 
JasperExportManager.exportReportToPdfFile(jasperPrint, "D:/reports/vehicle2_jasper.pdf");
 
 
   int len = (int)new File("D:/reports/vehicle2_jasper.pdf").length(); 
response.setContentLength(len); 
byte[] buf = new byte[len]; 
FileInputStream pdfin = new FileInputStream("D:/reports/vehicle2_jasper.pdf"); 
pdfin.read(buf); 
pdfin.close(); 
OutputStream pdfout = response.getOutputStream(); 
pdfout.write(buf,0,len); 
pdfout.flush();  
 
request.getRequestDispatcher("/vehicleReport.jsp").forward(request, response);
 
 
}
catch(Exception e){e.printStackTrace();}
finally{
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
 
and in vehicleReport.jsp I am trying to display the report as,
<object data="D:/reports/vehicle2_jasper.pdf" type="application/pdf">
<embed src="D:/reports/vehicle2_jasper.pdf" type="application/pdf">
</object>
 
but its not showing anything. .  How to solve this. can anyone help me in this.
 
 
 
 
 
raghavendram040's picture
Joined: Jun 26 2014 - 4:27am
Last seen: 4 years 3 months ago

0 Answers:

No answers yet
Feedback
randomness