Open JasperReport File in new Window of webBrowser

57 1 1 4

Hi I want open a jasperreport output file generated in new Window of browser
Im trying:
Executions.getCurrent().sendRedirect("the_url_generated_of_report","_blank");

but I can not found a method that returns me the url of output file generated by Jasper
Exists anyone way to solve this problem?
thanks so much!!!

delete retag edit

13 Replies

robertlee
561

If you know your output URL then you should try to pass the value by using setAttribute method or the custom-attribute component. See:

http://www.zkoss.org/doc/devguide-single/index.html#id459905

Hope this helps.

57 1 1 4

thanks
but my question is how I can obtain the_url_generated_of_report? y was research in source code of jasperreport component and am not found anyone method that returns me it

robertlee
561

How do you set your output directory?

dennis
3669 1 6
http://www.javaworld.com....

please post it to feature request .

xmedeko
1031 1 16
http://xmedeko.blogspot.c...

Hi,

this is a little bit old thread, but I have seen more people asking this, so one solution is here: http://zh.zkoss.org/forum/listComment/2677

But I think this solution is too much memory consuming - the whole PDF stored in session. Also, the user cannot "reload" the report. And the PDF will stay in the session, if something wrong happens and the client browser would not trigger the jasperreport servlet. At least the soft references should be used, to avoid out of memory error.

Other solution it to pass into the session just the Jasper Report, like # net.sf.jasperreports.j2ee.servlets.PdfServlet. But again, soft references should be used.

IMHO the best solution is the old good way of passing to the "jasperreport servlet" just a few parameters in URL query string, e.g. ?id1=XXX&id2=YYYY and then the servlet should create the report.

If you cannot pass parameters in URL, then put them into the session, usually they will take much less memory then the PDF. In this situation you can use soft/weak references in this way. Usage of weak references:
- store the parameters in the original desktop/page
- make a weak references and store them into the session, or use weak hash map
- open "jasperreport servlet" in a new window. the user can now reload "reload" the report as long as the weak references exists, that is as long as the original desktop/page exists

9393 3 7 16
http://www.oxitec.de/

smigol
316 2
I agree with @xmedeko
@intoxicadocoder, however I use JasperReport since 4 years to produce real-time reports ... I never stored report in session or file-system server ...
In my application, I open a new window and call a Custom JasperReport Servlet passing parameters (POST method ... but you can also pass in GET) ...
below, that's all step to create one servlet Custom JasperReport Servlet:
1) Compile. Jrxml to. Jasper if it has been updated externally (it's optional, you can use directly. Jasper compiled file):
use
JasperReport jasperReport = JasperCompileManager.compileReportToFile (java.lang.String sourceFileName,
java.lang.String destFileName)


2) Fill. Jasper with the data (ex. your params can be used to retrieve data from a database with a custom query)
use
JasperPrint jasperPrint = JasperFillManager.fillReport (JasperReport jasperReport,
java.util.Map parameters,
JRDataSource dataSource)


where
JasperReport jasperReport = (JasperReport) JRLoader.loadObject (jasperFilePath)
JRDataSource dataSource = new JRResultSetDataSource(<b >Resultset</b>);

3) Export the report in your preferred format using an extension of :
JRAbstractExporter

- PDF: JRPdfExporter
- XML: JRXmlExporter
- XLS: JRXlsExporter
- CSV: JRCsvExporter
- TXT: JRTextExporter


... and passing in JRAbstractExporter.setParameters, the param of output type:
- TO FILE: JRAbstractExporter.OUTPUT_FILE_NAME filePathDestinationStr
- TO STREAM: JRAbstractExporter.OUTPUT_STREAM outputStreamObject


example:
httpResponse.setContentType("application/pdf");
ServletOutputStream out = httpResponse.getOutputStream();

//STEP 1: COMPILE REPORT (OPTIONAL ... U CAN USE DIRECTLY .jasper FILE AND SKIP THIS STEP)
JasperReport jasperReport = ....
....
....

//STEP 2: FILL REPORT
JasperPrint jasperPrint = ....
....
....

//STEP 3: EXPORT REPORT AND PUT INTO SERVLETOUTPUTSTREAM

JRAbstractExporter exporter = JRPdfExporter();
Map<JRExporterParameter, Object> parameterExport = new HashMap<JRExporterParameter, Object>();
parameterExport.put((JRExporterParameter.JASPER_PRINT, jasperPrint);
parameterExport.put((JRPdfExporterParameter.OUTPUT_STREAM,out);
exporter.setParameters(parameterExport):
exporter.exportReport();

out.flush();



go to http://sourceforge.net/projects/jasperreports/files/jasperreports and download jasperreports-3.7.1-project.tar.gz Project Source Files ... look for demo/samples or demo/samples/webapp ... u can find more example!!
Regards

PeterKuo
481 2

@smigol

xmedeko
1031 1 16
http://xmedeko.blogspot.c...

@PeterKou FYI, I have opened this thread again, because it is linked from http://docs.zkoss.org/wiki/Jasper. (Although the link is old, I will update it).

RFSLUX
75

Hi smigol,

[email protected] for your post. This morning I start to integrate jasper in our project and your post helps me a lot !
Only two hints from me, which costs me a little time, and may help anyone.....

I use iReport 3.7.4 to design and compile the reportfile.
The following code:

JasperPrint jasperPrint = JasperFillManager.fillReport(session.getWebApp().getRealPath("/WEB-INF/jasper/report3.jasper"), new HashMap(),source);


Only gets exception: net.sf.jasperreports.engine.JRRuntimeException: Unknown hyperlink target 0
Using zk5.03PE

Problem seems: compability issue
If there are compability problems with compiled files and jasper-lib the save way is to compile at runtime.

To compile at runtime I need Apache commons-beanutils-.jar and commons-digester.jar to add to WEB-INF/lib
@ZK-Team: Maybe an idea to add this to zkpe-bin-5.0.3\dist\lib\ext ???

Best regards,
Jörg

[hide preview]