开发者

HTTP Header Mime Type in Websphere Application Server 7

开发者 https://www.devze.com 2023-03-16 02:48 出处:网络
I have a Spring Web Application where a user can download PDF and Excel Files. I set the HTTP header for both of them:

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);
    respon开发者_开发技巧seHeaders.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?


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消