Jump to content

when click the save button,PDF should be opened


anupp

Recommended Posts

Hi,
  I have generated PDF report in destination folder i.e. C Drive.But My Requirement is when click the save button,PDF should be opened. please check the code and where i m missing in this code.I have used jasper view .viewReport its generated but problem is when jasper view part is  closed then automatic weblogic server is terminating..Please find the attachement..

Thanks in advance
 

Code:
       reportDataSource = new JRMapCollectionDataSource(reportdataList);               JasperPrint jasperPrint;                HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();                String reportPath =request.getSession().getServletContext().getResource("/reports").toString().substring(6); // substring cuts off the 'file://'                               File file = new File(reportPath + "TransferSecretaries_Report.jasper");                String file1 = file.toString();                 Random generator = new Random();                int reportId = generator.nextInt();                String dest ="c:/report_"+reportId+".pdf";                              String destFileName = "transferReport"+reportId+".pdf";                                  try {                     jasperPrint =JasperFillManager.fillReport(file1, new HashMap(),reportDataSource);                    System.out.println("jasper printing>>>>>>>>>>>>>>>>>"+jasperPrint);                    response.setContentType("application/pdf");                  //  OutputStream ouputStream = new FileOutputStream(new File(dest));              OutputStream ouputStream                  = new FileOutputStream(new File("dest"));                     JRPdfExporter exporter = new JRPdfExporter();                     exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);                    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);              JasperExportManager.exportReportToPdfStream(jasperPrint, ouputStream);                    System.out.println("exporter pdf file calling>>>>>>>>>>>>");                    exporter.exportReport();                    ouputStream.flush();                    ouputStream.close();                   HttpServletResponse response = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();                    response.sendRedirect("/reports"+ouputStream);          } catch (JRException e) {            } catch (FileNotFoundException e) {            } catch (IOException e) {            }        }

Post Edited by anupp at 06/12/2010 14:13
Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

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...