IE对http1.1 不支持201状态码(待确定)

来源:互联网 发布:mac os升级不支持银联 编辑:程序博客网 时间:2024/06/02 04:06
 

IE对http1.1 不支持201状态码

标签: springIE浏览器download
 1286人阅读 评论(0) 收藏 举报
 分类:

最近用spring MVC做一个文件下载程序的时候,发现IE对HttpStatus.CREATED状态的并非完全支持

如:

[java] view plain copy
 print?
  1. @RequestMapping(value = "/download", method = RequestMethod.POST )  
  2.     @ResponseBody  
  3.     public ResponseEntity<byte[]> download(  
  4.             @RequestParam("fileName") String fName) throws IOException {  
  5.         System.out.println(fName);  
  6.         String path = this.servletContext.getRealPath("/WEB-INF/load") + "\\aaa\\" + fName;  
  7.         System.out.println(path);  
  8.         HttpHeaders headers = new HttpHeaders();  
  9.         headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);  
  10.         headers.setContentDispositionFormData("attachment"new String(fName.getBytes("GBK"),"ISO8859-1"));  
  11.         File file = new File(path);  
  12.         if(file.exists()){  
  13.             return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(  
  14.                         file), headers,HttpStatus.CREATED);  
  15.         }  
  16.         headers.setContentDispositionFormData("attachment""error.txt");  
  17.         return new ResponseEntity<byte[]>("发送错误.".getBytes(), headers,  
  18.                 HttpStatus.CREATED);  
  19.   
  20.     }  

在IE中并不能下载,而在其他浏览器是可以下载的,但是下面的代码却可以

[java] view plain copy
 print?
  1. @RequestMapping(value = "/download", method = RequestMethod.POST )  
  2.     @ResponseBody  
  3.     public ResponseEntity<byte[]> download(  
  4.             @RequestParam("fileName") String fName) throws IOException {  
  5.         System.out.println(fName);  
  6.         String path = this.servletContext.getRealPath("/WEB-INF/load") + "\\aaa\\" + fName;  
  7.         System.out.println(path);  
  8.         HttpHeaders headers = new HttpHeaders();  
  9.         headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);  
  10.         headers.setContentDispositionFormData("attachment"new String(fName.getBytes("GBK"),"ISO8859-1"));  
  11.         File file = new File(path);  
  12.         if(file.exists()){  
  13.             return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(  
  14.                         file), headers,HttpStatus.OK);  
  15.         }  
  16.         headers.setContentDispositionFormData("attachment""error.txt");  
  17.         return new ResponseEntity<byte[]>("发送错误.".getBytes(), headers,  
  18.                 HttpStatus.OK);  
  19.   
  20.     }  
原创粉丝点击