HTTP Header Mime Type in Websphere Application Server 7

只谈情不闲聊 提交于 2019-12-08 09:36:38

问题


I have a Spring Web Application where a user can download PDF and Excel Files. I set the HTTP header for both of them:

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.parseMediaType("application/vnd.ms-excel"));
    responseHeaders.setContentLength(fileSize);
    responseHeaders.set("Content-Disposition", "attachment");
    responseHeaders.add("Content-Disposition", "filename=\"" + encodedFileName + '\"');

This works fine on Tomcat (the HTTP response is of mime type application/vnd.ms-excel). But on Websphere 7, the server always return content type: text/html for this request.

I have already registered the excel content type in the web sphere virtual host, but this does not change anything.

What did I missed?


回答1:


Your syntax is incorrect, you can't have multiple C-D headers. Like this:

responseHeaders.set("Content-Disposition", "attachment; filename=\"" + encodedFileName + '\"');

Also, the code will not work correctly when encodedFilenName contains characters outside the ISO-8859-1 character set.

(dunno whether that's related to your problem, though)



来源:https://stackoverflow.com/questions/6493192/http-header-mime-type-in-websphere-application-server-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!