Rizwan Merchant wrote:



I am working on a web application using the Struts framework. Using a form on a jsp page, I generate a report which is displayed in pdf on a new screen. The report is generated through an Action class method. I would like to display a "Please wait" screen while the report is being generated.

The action class method calls functions that generate a pdf file and then redirects control to that file. So I cannot use the flush() method to send html to the browser while the report is being generated (once a response is committed it cannot be written to again). Neither can I use the 'div' tag method as my new page is not a jsp page (it is a new browser window with pdf file displayed inside it).

One common strategy for this sort of thing is to refactor your action into several, along the following lines:


* The Action that is currently creating the PDF should instead
 fire off a background thread to do the report preparation.  It
 will then forward to a "Please Wait" page (see below).

* The background thread should do whatever is needed to prepare
the PDF file, and set a flag variable in the user's session when it's done,
followed by terminating the thread.


* The "Please Wait" page should say something like "Report generation
 in progress", and use a meta-refresh tag to automatically submit itself
 every few seconds, with the destination being a "Done Yet" action.

* The "Done Yet" action will consult the flag variable in the user's session.
If its not there, forward back to the "Please Wait" page again. If it's
done, forward to the URL to retrieve the PDF itself.


Craig



My code is shown below....

//the jsp code calling the action
<nested:form action="/reports.do?action=getTransactionReports" target="_blank">



// The Action class
public ActionForward getTransactionReports(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception
{


ICustomerAdministrationClient admin_impl = getCustomerAdministrationService(request);

//enforce user permission
enforceFeaturePermissions(EMSConstants.FEATURE_REPORTS, request, 1);

EMSBaseAdminForm admin_form = (EMSBaseAdminForm)form;
ReportsForm reportsForm = admin_form.getReportsForm();

//cant do this as it creates an IllegalStateException
// PrintWriter html = response.getWriter();
//
// html.print("<html>\n<head><title>my test</title></head>\n<body>");
// html.print("<p><img src=\"images/dpt_logo.jpg\"></body></html>");
// html.flush();
// html.close();


//if details type is summary then output format can only be PDF if(reportsForm.getDetailsType().equals(EMSConstants.REPORTS_SUMMARY)) reportsForm.setOutputFormat(EMSConstants.REPORTS_FORMAT_PDF);

//generate the reports using jasper reports
doJasperReports(reportsForm, request);

CustomerForm customer_form = (CustomerForm)getSessionObject(request, "customerForm");
Collection all_region_list_forms = (Collection)getSessionObject(request, "allRegionListForms");


admin_form.setCustomerForm(customer_form);
admin_form.setRegionListForms(all_region_list_forms);
request.setAttribute(EMSConstants.FORM_VIEW, admin_form);

String relativePath = File.separator + "temp_" + request.getSession().getId();
String pdfFilePath = File.separator + "temp" + relativePath + File.separator + "ReportinPDF.pdf";
String csvFilePath = File.separator + "temp" + relativePath + File.separator + "ReportinCSV.dpt";


if(reportsForm.getOutputFormat().equals(EMSConstants.REPORTS_FORMAT_PDF))
return (new ActionForward(pdfFilePath, true));

return (new ActionForward(csvFilePath, true));
}


Any help would be appreciated. Thanks. ------------------------------------------------------------------------

<http://www.digitalpaytech.com/>



Rizwan Merchant - Software Developer
4105 Grandview Highway, Burnaby, BC, V5C 6B4, Canada
Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
Phone: 604-688-1959 x243 Fax: 604-687-4329 Toll Free: 1-888-687-6822 Website: www.digitalpaytech.com <outbind://11/www.digitalpaytech.com>






--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to