下载模板

2019-03-29  本文已影响0人  欧_汤姆
// 浏览器下载excel模板
    public void downloadTemplate(HttpServletResponse response,HttpServletRequest request) throws Exception {
        String fileName="导出模板.xls";
        response.reset();
        response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
            String filePath=request.getServletContext().getRealPath("/excel/")+fileName;
            FileInputStream input=new FileInputStream(filePath);
            OutputStream out=response.getOutputStream();
            byte[] b=new byte[2048];
            int len;
            while((len=input.read(b))!=-1) {
                out.write(b,0,len);
            }
             response.setHeader("Content-Length", String.valueOf(input.getChannel().size()));
                input.close();
    }
上一篇 下一篇

猜你喜欢

热点阅读