前端js文件:window.open(“feeWarning/excelQfAll”);//访问后台springmvc中的excelQfAll方法得到下载的资源
采用的springmvc框架
后台java文件:
public void excelQfAll(HttpServletRequest request,HttpServletResponse response) {
String filename=request.getSession().getServletContext().getRealPath(“/static/email/”);
String filenameZip=filename+”\\email.zip”;
try {
response.setContentType(“application/x-execl”);
response.setHeader(“Content-Disposition”, “attachment;filename=” + new String((“email.zip”).getBytes(), “UTF-8”));
//读取文件
InputStream in = new FileInputStream(filenameZip);
ServletOutputStream outputStream = response.getOutputStream();
//写文件
int b;
while((b=in.read())!= -1)
{
outputStream.write(b);
}
in.close();
outputStream.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}