/** * 导出项目中的excel模板 * * @param request * @param response * @throws FileNotFoundException */ @RequestMapping(params = "templateDownload") public void templateDownload(HttpServletRequest request,HttpServletResponse response) throws FileNotFoundException { InputStream inputStream =null; ServletOutputStream out = null; try { //设置response的编码方式 response.setContentType("text/html;charset=UTF-8"); //设置附加文件名 response.setHeader("Content-Disposition","attachment;filename="+ URLEncoder.encode("楼盘价格模板.xls", "UTF-8")); //文件路径 String path = request.getSession().getServletContext().getRealPath("\\") + "plug-in\\hjyzg\\excel\\楼盘价格模板.xls"; inputStream = new BufferedInputStream(new FileInputStream(path)); out = response.getOutputStream(); byte[] data = new byte[4 * 1024]; int bytesRead; while ((bytesRead = inputStream.read(data)) != -1) { out.write(data, 0, bytesRead); } } catch (IOException e) { e.printStackTrace(); } finally { try { out.close(); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }