Jump to content
We've recently updated our Privacy Statement, available here ×

empty pdf file when downloading through browser


my5906

Recommended Posts

hi,

I made jasper file using iReport.

In iReport preview...PDF file excutes and works perfect.

In java program...there is no error but an empty PDF when downloading through IE browser.

I can see pdf333 start------------, pdf333 end--------- code below through server log.

 

Here's the source...plz help me T_T

Connection conn = null;

  String gbm2 = "";
 String ctrt_code = request.getParameter("CTRT_CODE") == null ? "" : request.getParameter("CTRT_CODE");
 
 String reportName = request.getRealPath("/")+"reports\test.jasper";

    DBSource ds  = new DBSource();
    conn = ds.getConnection(gbm2);

    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    }
   
    try {


     System.out.println("pdf333 start-----------------------------------------------------");
     InputStream is = new FileInputStream(reportName);

     HashMap map = new HashMap();
     map.put("ctrt_code", ctrt_code);
   
   ArrayList printList = new ArrayList();

   JasperPrint jasperPrint = JasperFillManager.fillReport(request.getRealPath("/")+"reports\test.jasper", map, conn);
    printList.add(jasperPrint);
    
   ServletOutputStream servletOutputStream = response.getOutputStream();      
 
   String filename =  ctrt_code+".pdf";
 String dnFilename = new String(filename.getBytes("MS949"), "ISO-8859-1");
 response.setContentType("application/pdf");
 response.setHeader("Content-Disposition",  "attachment; filename=" +  filename + ";");
       JRPdfExporter exporter = new JRPdfExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, printList);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);
        exporter.exportReport();  
       
     System.out.println("pdf333 end-----------------------------------------------------");
    
    } catch (JRException ex) {
     
        throw new ServletException(ex);
    } catch (NullPointerException e1) {
 
 
}     

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...