I used http request and http response to generate report before, use struts should be similar.
public void saveReport( HttpServletRequest pRequest,
HttpSession pSession )
//get your own data, you can ignor this part.
HashMap map = getData( pRequest, pResponse, pSession );
Report report = new MyReport();
String reportData =
report.generateReportToString( (Hashtable)map.get( "header" ),
(Enumeration)map.get( "data" ) );
//set your report type
pResponse.setContentType( "application/vnd.ms-excel" );
//if you want to save the report as a file Force browser to show save as dialog and give default file name.
"attachment; filename="+DEF_REPORT_NAME );
pResponse.setContentLength( reportData.length() );
pResponse.getWriter().print( reportData );
Hope this help.
From: Sharma Vedula [mailto:firstname.lastname@example.org]
Sent: Tuesday, November 19, 2002 9:51 AM
Subject: Exporting data to an excel spreadsheet
I have a web application written using Struts 1.2.
One of the pages displays a table of data. I have a
button on it which when clicked need to export all
that data to a Excel spreadsheet. I am a novice in
struts and would really appreciate any direction you
can give. I have been looking at apache's POI, but do
not know how to implement it in my application.
Any suggestions will be greatly appreciated.
Ph: 770-642-9708 (Home)
1115 Lyndhurst Way
Roswell, GA 30075
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site