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 = 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 = new byte[2];//要下載的數據流
        return new ResponseEntity<byte[]>(data, headers, HttpStatus.OK);
    }

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM