Java : Unable to change 'Content-Disposition' attribute in the Header for a response
Below is the code:
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);
}
As you can see, I have explicitly tried to change the 'Content-Disposition' to 'attachment' in the Heade开发者_高级运维r. But still, when I open an MS Office document, the HTTP Header data shows it as 'inline': Content-Disposition: inline; filename="New%20Microsoft%20Office%20Word%20Document.docx"
Do you think I should do anything else to set this right?
I suspect that the resource.serve
method call internally overwrites the header with its own value.
The javadoc says :
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.
精彩评论