注意,我这里的报错情况是输出流 outputstrea是在java层生成的,controller中通过response.getOutputStream(); 获取jsp输出流,再输出到jsp页面,下载文件。
如果下载文件的代码是在jsp页面的,请参考其他百度结果。
Controller:
public OutputStream downloadXLSTargetFile(HttpServletResponse response,String fileName)
{
File f = null;
if(fileName != null && !"".equals(fileName)){
f = new File(fileName);
}
//导出文件
try {
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition",
"attachment; filename=" + f.getName());
OutputStream out = response.getOutputStream();
return out;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
上面方法返回jsp输出流,将需要下载的文件流赋值给上面这个out变量,然后就返回jsp页面
@Re