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