Spring MVC 檔案下載時候 發現IE不支援
阿新 • • 發佈:2018-11-12
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=newString(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); }