本文介紹了如何在 JSP 中動態設置標頭值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我有一個創建 Excel 文檔的 JSP 文件.
I have a JSP file which creates an Excel document.
我想動態設置要下載的文件名.
I want to dynamically set the name of the file to be downloaded.
這就是我將文件名設置為test.xsl"的方式:
This is how I set the file name to "test.xsl":
<% response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment; filename=" + "test.xsl" );
%>
如何將文件名設置為 test-${今天的日期}.xsl(即 test-20100805.xsl)?
How can I set the file name to be test-${today's date}.xsl ( i.e. test-20100805.xsl ) ?
推薦答案
String fname = MessageFormat.format(
"test-{0,date,yyyyMMdd}.xsl", new Object [] { new Date() } );
response.setHeader("Content-Disposition","attachment; filename=" + fname );
我認為這應該適合你.
大括號中的文本告訴 MessageFormat
類從給定數組中插入值 0
,使用格式將其格式化為 date
yyyyMMdd
(例如 20161231
表示 2016 年 12 月 31 日).
The text in the braces tells the MessageFormat
class to insert value 0
from the given array, format it as a date
using the format yyyyMMdd
(e.g. 20161231
for Dec 31st 2016).
這篇關于如何在 JSP 中動態設置標頭值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!