public void downPersonImportTemplate(HttpServletRequest request, HttpServletResponse response) throws IOException { // 获取需要下载文件名称 String filename = "personImportTemplate.xls"; // 获取下载的类型 response.setContentType(request.getServletContext().getMimeType(filename)); // 告知客户端需要下载 response.setHeader("Content-Disposition", "attachment;filename=" + filename); // 获取文件的输入源 InputStream in = new BufferedInputStream(this.getClass().getResourceAsStream("/xlsTemplate/personImport.xls")); // 获取输出流 ServletOutputStream out = response.getOutputStream(); // 写出 int len = 0; byte[] buffer = new byte[1024]; while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); } in.close(); out.close(); }