gpt4 book ai didi

java - 下载的文件名在哪里设置?

转载 作者:行者123 更新时间:2023-12-02 04:15:34 25 4
gpt4 key购买 nike

我有一些代码来下载 pdf 文件,如下所示:

byte[] text = textContent.getText();
InputStream inputStream = new ByteArrayInputStream(text );
response.setContentType("application/pdf");
ServletResponseUtil.write(response, inputStream);

文件已成功下载,但名称来自何处?

最佳答案

您可以在响应 header 中指定文件名。

response.setContentType("application/pdf");
response.addProperty("Content-Disposition", "attachment; filename=" + myFilename);

这里假设资源是在 portlet 的资源阶段提供的。

有关 Content-Disposition 选项的完整列表,请参阅 RFC 6266 .

只要没有 Content-Disposition header ,浏览器就会从请求 URL 中获取文件名。

关于java - 下载的文件名在哪里设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33360475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com