OutputStream output; try { output = response.getOutputStream(); //清空缓存 response.reset(); //定义浏览器响应表头,顺带定义下载名,比如students(中文名需要转义) String s = file.getName() + file.getBirthday(); response.setHeader("Content-disposition", "attachment;filename=" + new String(s.getBytes(), "iso-8859-1") + ".xls"); //定义下载的类型,标明是excel文件 response.setContentType("application/vnd.ms-excel"); //这时候把创建好的excel写入到输出流 wb.write(output); //养成好习惯,出门记得随手关门 output.close(); } catch (IOException e) { e.printStackTrace(); }