1

我正在使用Spring处理JasperReports。我让客户有机会下载 pdf 和 csv 格式的报告。但我的要求是在下载提示中我需要显示带有日期和时间的文件名。但我只能显示文件名。下载时如何显示带有日期和时间的文件名?

我在jasper-views.xml中使用以下代码:

<bean id="test-pdf"
          class="org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView"
          p:url="classpath:reports/testreport.jrxml"
          p:reportDataKey="datasource">
          <property name="headers">
         <props>
             <prop key="Content-Disposition">
                  attachment; filename=TestReport.pdf
             </prop>
         </props>
     </property>
   </bean>

下载时如何在文件名中添加日期和时间?

4

2 回答 2

1

在写你的流之前,设置文件名:

response.setHeader("Content-Disposition", "inline; filename=" + fileName);

在文件名中,您可以动态设置日期:),此链接可能有用: securly-download-file-inside-browser-with-correct-filename

于 2013-10-01T14:10:44.733 回答
-1

In your example, you're able to show the filename because you can also specify what the filename should be when you actually generate the report. If you want to display the date and time the report is generated, and the report is generated when they press some button to download the report, you're really just displaying the current time. I don't know what value there is in that, but if it's necessary, just use some javascript to continually update the current time in their browser, maybe using a timer that fires once a minute to update the displayed time.

于 2013-09-30T13:03:02.233 回答