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

xiaoxiao2021-02-28  83

 

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

标签: springIE浏览器download

2014-01-14 22:37 1286人阅读 评论(0) 收藏 举报

 分类:

spring学习之路(5) 

版权声明:本文为博主原创文章,未经博主允许不得转载。

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

如:

 

[java] view plain copy  print?

@RequestMapping(value = "/download", method = RequestMethod.POST )      @ResponseBody      public ResponseEntity<byte[]> download(              @RequestParam("fileName") String fName) throws IOException {          System.out.println(fName);          String path = this.servletContext.getRealPath("/WEB-INF/load") + "\\aaa\\" + fName;          System.out.println(path);          HttpHeaders headers = new HttpHeaders();          headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);          headers.setContentDispositionFormData("attachment", new String(fName.getBytes("GBK"),"ISO8859-1"));          File file = new File(path);          if(file.exists()){              return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(                          file), headers,HttpStatus.CREATED);          }          headers.setContentDispositionFormData("attachment""error.txt");          return new ResponseEntity<byte[]>("发送错误.".getBytes(), headers,                  HttpStatus.CREATED);        }  

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

 

 

[java] view plain copy  print?

@RequestMapping(value = "/download", method = RequestMethod.POST )      @ResponseBody      public ResponseEntity<byte[]> download(              @RequestParam("fileName") String fName) throws IOException {          System.out.println(fName);          String path = this.servletContext.getRealPath("/WEB-INF/load") + "\\aaa\\" + fName;          System.out.println(path);          HttpHeaders headers = new HttpHeaders();          headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);          headers.setContentDispositionFormData("attachment", new String(fName.getBytes("GBK"),"ISO8859-1"));          File file = new File(path);          if(file.exists()){              return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(                          file), headers,HttpStatus.OK);          }          headers.setContentDispositionFormData("attachment""error.txt");          return new ResponseEntity<byte[]>("发送错误.".getBytes(), headers,                  HttpStatus.OK);        }  
转载请注明原文地址: https://www.6miu.com/read-81293.html

最新回复(0)