How can I change a JasperReport's actual name?

2019-03-05 02:56发布

问题:

I am using Java to generate a PDF of a compiled jasper report. The pre-compiled report has the name 'statsReport'. The report generates properly. The problem is when comes the time to save the file. I try changing the report name through the JasperPrint object (jasperPrint.setName('statsReport_20110718.pdf')). I do this because the user's expecting the file to save with a language specific name (French or English) and the date.

When using Firefox set to prompt before executing an action (Open in reader or Save as file), the filename I passed is used as expected ('statsReport_20110718.pdf'). The problem is when the browser setting is to open pdf automatically in Firefox/IE. The report opens correctly but when the user wants to save the file, it displays the pre-compiled jasper report name ('statsReport').

JasperReport class does not have a setName method that might have been useful.

Does anyone have any ideas?

Richard

回答1:

Set a HTTP Header in your servlet response like:

Content-Disposition: filename=statsReport_20110718.pdf