java IE不加载图像
@RequestMapping(value = "/performer/{id}", method = RequestMethod.GET)
public void getPortfolioFile(HttpServletResponse response,
@PathVariable("id") int id){
File image = getFile(id);
if(image != null){
try {
FileCopyUtils.copy(FileCopyUtils.copyToByteArray(image), response.getOutputStream());
String mimeType = image.toURL().openConnection().getContentType();
response.setContentType(mimeType);
response.setContentLength((int)image.length());
response.setHeader("Content-Disposition", "attachment; filename=\"" + image.getName() + "\"");
}catch (IOException e) {
e.printStackTrace();
}
}
}
正如你在回复中看到的,有一张图片,但没有显示在页面上
这种方法适用于FF、Chrome和Opera,但不适用于IE。 我使用IE v10
# 1 楼答案
改变顺序:首先写标题
然后是内容
否则,如果映像大于响应缓冲区,则由于响应已提交,因此会愚蠢地删除头并不发送
浏览器可能会对发送的内容感到困惑