HTTP Header Mime Type in Websphere Application Ser

2019-06-09 01:34发布

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条回答
家丑人穷心不美
2楼-- · 2019-06-09 02:10

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)

查看更多
登录 后发表回答