我有一些代码可以像下面这样下载pdf文件:
byte[] text = textContent.getText();
InputStream inputStream = new ByteArrayInputStream(text );
response.setContentType("application/pdf");
ServletResponseUtil.write(response, inputStream);
文件已成功下载了一些名称,但这些名称来自哪里?
您可以在响应标头中指定文件名。
response.setContentType("application/pdf");
response.addProperty("Content-Disposition", "attachment; filename=" + myFilename);
这里假设资源是在portlet的资源阶段提供的。
有关Content-Disposition
选项的完整列表,请参阅RFC 6266。
只要没有Content-Disposition
标头,浏览器就会从请求URL中获取文件名。