anupp Posted June 9, 2010 Share Posted June 9, 2010 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 More sharing options...
lucianc Posted June 17, 2010 Share Posted June 17, 2010 Follow-up at http://jasperforge.org/plugins/espforum/view.php?group_id=102&forumid=103&topicid=75289Please refrain from double posting.Regards,Lucian Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now