java web 下载本地文件并弹出下载框

 window.open("/dept/download")

jsp代码

 @RequestMapping(value = "/download", method = RequestMethod.GET)
public void downstudents(HttpServletRequest request, HttpServletResponse response) throws IOException {
String filename = request.getSession().getServletContext().getRealPath("/static/email/");
String filenameZip = filename + "\\dept.xls"; try {
response.setContentType("application/x-execl");
response.setHeader("Content-Disposition",
"attachment;filename=" + new String(("dept.xls").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();
} }

javaCode

上一篇:Burp Suite Pro 教程


下一篇:DB太大?一键帮你收缩所有DB文件大小(Shrink Files for All Databases in SQL Server)