前端jsp(简略):
<!-- 报盘模板下载 --> <a href="${base!}/get_template.do" style="cursor: point;text-decoration: underline;font-size: 14px;display: inline-block;float: right;margin-right: 10px;color: #007bbf;background-color:#f5fafc;line-height:35px;">模板下载</a>servlet:
@RequestMapping("get_template.html") public void downloadTemplate(HttpServletRequest request, HttpServletResponse response){ OutputStream out = null; try { String path = request.getsession().getServletContext().getRealPath("/"); String fileName = new String(("报盘模板.xls").getBytes("GBK"), "ISO8859_1"); response.setContentType("application/vnd.ms-Excel"); response.setHeader("Content-disposition", "attachment;filename=/"" + fileName + "/""); out = response.getOutputStream(); String filePath = path + "/WEB-INF/excelTemplate/pbpweb.xls"; InputStream inputSteam =new FileInputStream(filePath); HSSFWorkbook wb = new HSSFWorkbook(inputSteam); inputSteam.close(); wb.write(out); wb.close(); } catch (Exception ex) { ex.PRintStackTrace(); } finally { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } }报盘模板存放位置:
项目根目录:
/WEB-INF/excelTemplate/pbpweb.xls
新闻热点
疑难解答