首页 > 代码库 > Spring MVC 文件下载时候 发现IE不支持

Spring MVC 文件下载时候 发现IE不支持

@RequestMapping("download")    public ResponseEntity<byte[]> download(Long fileKey) throws IOException {        HttpHeaders headers = new HttpHeaders();        String fileName=new String(massMessage.getFileName().getBytes("UTF-8"),"iso-8859-1");        headers.setContentDispositionFormData("attachment", fileName);        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);        byte[] data = http://www.mamicode.com/new byte[2];//要下载的数据流        return new ResponseEntity<byte[]>(data, headers, HttpStatus.CREATED);    }

 

下载时提示:

下载时提示ie无法打开该站点,请求的站点不可用或找不到

类似信息

修改为下面的就OK了,主要是HttpStatus.CREATED修改为HttpStatus.OK

原因是IE 不支持201的状态码,修改为200就行了

 

@RequestMapping("download")    public ResponseEntity<byte[]> download(Long fileKey) throws IOException {        HttpHeaders headers = new HttpHeaders();        String fileName=new String(massMessage.getFileName().getBytes("UTF-8"),"iso-8859-1");        headers.setContentDispositionFormData("attachment", fileName);        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);        byte[] data = http://www.mamicode.com/new byte[2];//要下载的数据流        return new ResponseEntity<byte[]>(data, headers, HttpStatus.OK);    }