springle mvc中如何下载文件呢?
比struts2 下载文件简单得多
先看例子:
@responsebody
@requestmapping(value = "/download",produces="application/octet-stream")
public byte[] downloadfile(httpservletrequest request, httpservletresponse response,string contenttype2)
throws ioexception {
byte[]bytes=fileutils.getbytes4file("d:\\temp\\cc.jpg");
response.addheader("content-disposition", "inline;filename=\"a.jpg\"");
return bytes;
}
在浏览器中访问:http://localhost:8080/tv_mobile/video/download
注意:
(1)使用注解@responsebody 表示action返回的内容直接作为应答体返回;
(2)通过produces 设置返回的content type;
(3)直接返回要下载的文件的二进制数组
参考:http://hw1287789687.iteye.com/blog/2188480