日期:2014-05-17  浏览次数:20712 次

spring MVC文件下载IE不能下载的问题
@RequestMapping(value = "/download", method = RequestMethod.POST )
@ResponseBody
public ResponseEntity<byte[]> download(
@RequestParam("fileName") String fName) throws UnsupportedEncodingException {
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"));
try {
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(
new File(path)), headers,HttpStatus.CREATED);
} catch (IOException e) {
e.printStackTrace();
}
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", "error.txt");
return new ResponseEntity<byte[]>("发送错误.".getBytes(), headers,
HttpStatus.OK);

}


<a href="<%=basePath%>upload">继续上传</a>
  <c:forEach items="${files}" var="file">
   <form action="download" method="post" >
   <label>${file.name}</label>
   <input type="submit" value="下载"/>
   <input type="hidden"  name ="fileName" value="${file.name}">
   </form>
  </c:forEach>

IE下不能下载,弹出保存或者打开download,谷歌浏览器可以正常下载,请高人指点。

------解决方案--------------------
我的method用的是get
------解决方案--------------------
其他浏览器可以?
------解决方案--------------------
谷歌和火狐都有firebug之类的查看工具,看头信息,再用httpwatch看下ie下头信息是什么,存在哪些差异,才好解决