@RequestMapping("/download") public void download(HttpServletResponse res ,HttpServletRequest req) throws IOException { OutputStream os = res.getOutputStream(); try { res.reset(); res.setHeader("Content-Disposition", "attachment; filename=down.xls"); res.setContentType("application/octet-stream; charset=utf-8"); os.write(FileUtils.readFileToByteArray(getDictionaryFile(req))); os.flush(); } finally { if (os != null) { os.close(); } } } private File getDictionaryFile(HttpServletRequest req) { File file =new File(req.getSession().getServletContext().getRealPath("/WEB-INF/down.xls")); return file; }
http://www.iteye.com/topic/1125784