Discussions
Categories
Choose a Product
THRUST SERVICES
CORE APPS
CE PRODUCTS
...
Quick Links
POPULAR
HELPFUL TIPS
Groups
My Links
FOR SIGNED IN MEMBERS:
Back to website
Home
Developing Analytics Applications
Web integration - download report with ajax servlet call
Migrateduser
<p>Hi,</p><p> </p><p>I got Birt integrated in my web app and can use the BirtViewer successfully if I wish.</p><p> </p><p>What I really need to accomplish is the following:</p><p> </p><p>I wish to have a button in my web page that upon pressing it an <span class='bbc_underline'><strong>ajax </strong></span>call will be made to a servlet which generates a report and the report is "downloaded" as PDF/DOC/XLS -> just like if I was using the viewer</p><p>and chose to export the report. </p><p> </p><p>I see in the console that the report is generated by nothing happens in the web page..</p><p>(I am expecting the report to be "downloaded").</p><p> </p><p>Your help is greatly appreciated.</p><p> </p><p>Thanks.</p><p> </p><p> </p><p>My servlet code is:</p><p> </p><div>response.setContentType( "application/pdf" ); </div><div>response.setHeader ("Content-Disposition","inline; filename=test.pdf");<span> </span></div><div>String reportName = report.getReportName();</div><div>ServletContext sc = request.getSession().getServletContext();</div><div>//<span> </span>this.birtReportEngine = BirtEngine.getBirtEngine(sc);</div><div> </div><div> </div><div>IReportRunnable design;</div><div>try</div><div>{</div><div>IReportEngine engine = null;</div><div> EngineConfig config = null;<span> </span> <span> </span> <span> </span></div><div> // Configure the Engine and start the Platform</div><div> config = new EngineConfig();</div><div> config.setEngineHome("C:/birt-runtime-2_1_1/birt-runtime-2_1_1/ReportEngine");<span> </span> <span> </span></div><div> Platform.startup(config);</div><div> final IReportEngineFactory FACTORY = (IReportEngineFactory) Platform.</div><div> createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);</div><div> </div><div> engine = FACTORY.createReportEngine(config);</div><div> <span> </span> <span> </span> </div><div> //Open report design</div><div> design = engine.openReportDesign("C:/reports/templates/"+sourceFile); </div><div> //create task to run and render report</div><div> IRunAndRenderTask task = engine.createRunAndRenderTask(design);<span> </span></div><div> task.addScriptableJavaObject("reportDataMap", reportData);</div><div> //set output options</div><div> HTMLRenderOption options = new HTMLRenderOption();</div><div> //set the image handler to a HTMLServerImageHandler if you plan on using the base image url.</div><div> options.setImageHandler(new HTMLServerImageHandler());</div><div> options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);</div><div> options.setOutputStream(response.getOutputStream());</div><div> options.setBaseImageURL(request.getContextPath()+"/images");</div><div> options.setImageDirectory(sc.getRealPath("/images"));</div><div> </div><div> task.setRenderOption(options);</div><div> </div><div> //run report</div><div> task.run();</div><div> task.close();</div><div> }catch (Exception e){</div><div> e.printStackTrace();</div><div> throw new ServletException( e );</div><div> } </div>
Find more posts tagged with
Comments
There are no comments yet