logudotcom Posted May 8, 2007 Share Posted May 8, 2007 Dear All, i have been using jasper report for a project. i did not write query in report query or query string(jasper report) instead query is constructed in java page and result is passed as a arraylist to the report to show the report i use acrobat reader. when i load the answer to the acrobat reader5.0 the result is not shown until i refresh the page but i can get the result in the first time itself. when i use acrobat reader version 6.0 and the above.so plz can any one say wheather it is a problem in version or the code need to be changed. the code is as follows. ServletOutputStream servletOutputStream = response.getOutputStream(); URL url = ClassLoader.getSystemResource ( "file:" + servlet.getServletContext ( ).getRealPath ( "reports" ) + "/sponsor/PrintLabel.jasper" ); if ( url == null ) url = new URL ( "file:" + servlet.getServletContext ( ) .getRealPath ( "reports" ) + "/sponsor/PrintLabel.jasper" ); response.setContentType ( "application/pdf" ); InputStream inputSt = url.openStream ( ); InputStream reportStream = inputSt; Sponsor[] spo=(Sponsor[]) listLabel.toArray(new Sponsor[0]); JRBeanArrayDataSource beanCollectionDataSource = new JRBeanArrayDataSource ( ( spo ) ); JasperRunManager.runReportToPdfStream ( reportStream , servletOutputStream , new HashMap ( ) , beanCollectionDataSource ); servletOutputStream.flush ( ); servletOutputStream.close ( ); Link to comment Share on other sites More sharing options...
sphjava Posted April 10, 2008 Share Posted April 10, 2008 public ActionForward printReportTest(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { String sForward = null; //des_abs_all_districts.jrxml response.setContentType("application/pdf"); ServletContext application = getServlet().getServletContext();// uncomment the following line on linux // JRProperties.setProperty(JRProperties.COMPILER_CLASSPATH, application.getRealPath("/WEB-INF/lib/jasperreports-1.2.7.jar") + System.getProperty("path.separator") + application.getRealPath("/WEB-INF/classes/")); JRProperties.setProperty( JRProperties.COMPILER_TEMP_DIR, application.getRealPath("/reports/")); try { List report = new ArrayList (); JRDataSource beanArrayDataSource = null; Map p1 = null; File reportFile = null; JasperReport jReport = null; //report = new ReportManager().getAbstract4AllDistricts(Long.parseLong(request.getParameter("tenderid"))); ArrayList mem=new ArrayList (); mem.add("Prakash S"); mem.add("Suresh S"); mem.add("SVL"); TestReportForm f=new TestReportForm (); f.setHeadname("KS"); f.setMembers(mem); report.add(f) ; mem=new ArrayList (); mem.add("Prakash S 1"); mem.add("Suresh S 1"); mem.add("SVL 1"); f=new TestReportForm (); f.setHeadname("KS 1"); f.setMembers(mem); report.add(f) ; beanArrayDataSource = new JRBeanArrayDataSource((TestReportForm[]) report.toArray(new TestReportForm[0])); String src = application.getRealPath("/reports/" + "Main.jrxml"); net.sf.jasperreports.engine.design.JasperDesign jDesign = net.sf.jasperreports.engine.xml.JRXmlLoader.load(src); jReport = net.sf.jasperreports.engine.JasperCompileManager.compileReport(jDesign); p1 = new HashMap(); // p1.put("tendername", request.getParameter("tendername").toString()); reportFile = new File(application.getRealPath("/reports/Main.jrxml")); p1.put("SUBREPORT_DIR", String.valueOf(reportFile.getParentFile() + "/")); JasperPrint jPrint = JasperFillManager.fillReport(jReport, p1, beanArrayDataSource); OutputStream out = response.getOutputStream(); net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jPrint, out); } catch (Exception ex) { ex.printStackTrace(); } return null; } 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