在哪里下载文件名设置?

问题描述 投票:0回答:1

我有一些代码可以像下面这样下载pdf文件:

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

文件已成功下载了一些名称,但这些名称来自哪里?

java liferay liferay-6 portal
1个回答
2
投票

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

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

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.