SSM框架:
方法一:利用ResponseEntity处理
前台:
$('#downlink').attr('href','music/download?murl='+data.murl);
document.getElementById("downlink").click();
后台:利用流的形式,构建ResponseEntity响应报文
@RequestMapping(path="/download",method= RequestMethod.GET)
public ResponseEntity<byte[]> Download(HttpSession session,String murl){
try {
// 获得ServletContext
ServletContext servletContext = session.getServletContext();
// 下载文件的路径
String path = servletContext.getRealPath(murl);
// 判断文件是否存在
if(!new File(path).exists()){
byte[] body = new