下面是代码:
Resource resource = getResource(request, requestUrl, userInfo, objectIdParam,
rootFolderId, pathInfo, overrideCharset, isThumbnailResource);
// New line added to change Content-Disposition
response.setHeader( "Content-Disposition", "attachment;filename=" + pathInfo );
if (resource != null && resource.isServable()) {
resource.serve(request, response);
}
如您所见,我已明确尝试将 header 中的“Content-Disposition”更改为“attachment”。但是,当我打开 MS Office 文档时,HTTP header 数据将其显示为“内联”: 内容配置:内联; filename="New%20Microsoft%20Office%20Word%20Document.docx"
你认为我应该做些什么来纠正这个问题吗?
最佳答案
我怀疑 resource.serve
方法调用在内部用它自己的值覆盖 header 。
If the header had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.
关于Java : Unable to change 'Content-Disposition' attribute in the Header for a response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6926577/