View Full Version : Stored JasperReports generated file
Kimin
Aug 9th, 2007, 05:01 AM
I have successfully implemented spring + jasper using JasperReportsMultiFormatView
<bean id="reportView" class="org.springframework.web.servlet.view.jasper reports.JasperReportsMultiFormatView">
<property name="url" value="/WEB-INF/reports/master.jrxml"/>
<property name="jdbcDataSource" ref="dataSource"/>
<property name="subReportUrls">
<map>
<entry key="objective">
<value>/WEB-INF/reports/sub1.jrxml</value>
</entry>
<entry key="target">
<value>/WEB-INF/reports/sub2.jrxml</value>
</entry>
</map>
</property>
</bean>
...but except from just generate the report as a pdf to the user to be downloaded, i also want to 'store the file into the server'.
...as i could see the implementation in spring focused for the view on the user side
1. my question is could spring somehow get the generated report (any file generated pdf,xls or csv) and how to do it
2. could we trigger some process in the background ex: put some data such as the date the report generated into the DB.
this is my first post in the forums hope someone have any suggestion on the matter
noon
Aug 9th, 2007, 02:12 PM
This is just a thought.
Maybe you could implement an HTTP client application or scheduled job which calls the Spring Controller. After calling and receiving the binary PDF-file, you could save it to the disc.
As a HTTP client you could use Apache HttpClient which is really great doing stuff like this.
Scheduled jobs can be implemented by using Quartz.
Kimin
Aug 10th, 2007, 03:12 AM
hmmm.. that might work, but how can i get the binary PDF-file generated by JasperReportsMultiFormatView
but now with the config my application already can generate the pdf,xls,csv view to the user browser. so now it create a view as a file to the user and they already can get the file but i also want to save the file upon the user request into the application folder ex:/WEB-INF/reportlog/
i'm don't know how JasperReportsMultiFormatView create binary PDF-file and how to get it :confused:
Byapti
Aug 10th, 2007, 06:40 AM
Hi,
I think the JasperReports article on
http://aspalliance.com/1140_Creating_Report_Using_JasperReports may be helpful in this discussion.
This popular white paper is written by a software engineer from our organization Mindfire Solutions (http://www.mindfiresolutions.com).
I hope you find it useful!
Cheers,
Byapti
Kimin
Aug 10th, 2007, 11:01 PM
i finally sound a solution to my question :)
what i'm doing is create my own class that extends JasperReportsMultiFormatView
<bean id="reportView" class="org.appfuse.web.JasperViewTest">
<property name="url" value="/WEB-INF/reports/policy_master.jrxml"/>
<property name="jdbcDataSource" ref="dataSource"/>
<property name="subReportUrls">
<map>
<entry key="objective">
<value>/WEB-INF/reports/policy_subobjective.jrxml</value>
</entry>
<entry key="target">
<value>/WEB-INF/reports/policy_subtarget.jrxml</value>
</entry>
</map>
</property>
</bean>
my class:
public class JasperViewTestClass extends JasperReportsMultiFormatView{
private HttpServletRequest cRequest;
@Override
protected void renderReport(JasperPrint arg0, Map arg1, HttpServletResponse arg2) throws Exception {
//get the binary of the pdf file
byte[] bytes =JasperExportManager.exportReportToPdf(arg0);
FileUploadManager muploadMgr = new FileUploadManager();//my upload manager class
String uri = cRequest.getRequestURI();//ex: /myapplication/report_ABC.pdf
String format = uri.substring(uri.lastIndexOf("/") + 1);
String pExtension = uri.substring(uri.lastIndexOf("."));
//file cheking
String newFile = muploadMgr.checkFileAndRename("c:\\", format, pExtension);
//write file to disk
muploadMgr.writeFileToDisk(newFile, bytes);
super.renderReport(arg0, arg1, arg2);
}
@Override
protected void renderMergedOutputModel(Map arg0, HttpServletRequest arg1, HttpServletResponse arg2) throws Exception {
this.cRequest = arg1;//to store the current HttpServletRequest to this class
super.renderMergedOutputModel(arg0, arg1, arg2);
}
}
this works for me, and i think this class still can be improved.
any other suggestion ..
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.