Websphere Application Server 7中的HTTP标头Mime类型

我有一个Spring Web应用程序,用户可以下载PDF和Excel文件。 我为它们设置了HTTP标头:

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 + '\"'); 

这在Tomcat上工作正常(HTTP响应是mime类型application / vnd.ms-excel)。 但是在Websphere 7上,服务器始终返回此请求的内容类型:text / html。

我已经在web sphere虚拟主机中注册了excel内容类型,但这不会改变任何内容。

我错过了什么?

您的语法不正确,您不能有多个CD标头。 喜欢这个:

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

此外,当encodedFilenName包含ISO-8859-1字符集之​​外的字符时,代码将无法正常工作。

(不知道这是否与你的问题有关)