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

 

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?

  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.     }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值