zoukankan      html  css  js  c++  java
  • [功能集锦] 001

        @RequestMapping("/downloadxls.action")
        public void downloadxls(HttpServletRequest request, HttpServletResponse response) {
            //获取请求参数
            Map<String, Object> params = ParamsUtil.getParams(request);
            String contextPath = request.getSession().getServletContext().getRealPath(File.separator + "report");
            String excelName = xxxxx;
            String excelFullName = contextPath + File.separator + excelName + ".xls";
            InputStream inStream = null, fileInStream = null;
            ServletOutputStream outStream = null;
            int byteRead;
            try {
                fileInStream = new FileInputStream(excelFullName);
                inStream = new BufferedInputStream(fileInStream);
                response.reset();
                response.setContentType("APPLICATION/OCTET-STREAM");
                response.setHeader("Content-disposition", "attachment; filename=" + excelName + ".xls");
                outStream = response.getOutputStream();
                byte[] buffer = new byte[1024];
                while ((byteRead = inStream.read(buffer)) != -1) {
                    outStream.write(buffer, 0, byteRead);
                }
                response.flushBuffer();
                outStream.close();
                inStream.close();
                fileInStream.close();
            } catch (Exception e) {
                LOGGER.error( e);
            }finally{
                try {
                    if(outStream!=null){
                        outStream.close();
                    }
                } catch (IOException e2) {
                    LOGGER.error(e2);
                }
                try {
                    if(inStream!=null){
                        inStream.close();
                    }
                } catch (IOException e2) {
                    LOGGER.error(e2);
                }
                try {
                    if(fileInStream!=null){
                        fileInStream.close();
                    }
                } catch (IOException e2) {
                    LOGGER.error(e2);
                }
            }
        }
  • 相关阅读:
    题解 CF171G 【Mysterious numbers
    题解 P1157 【组合的输出】
    题解 P3955 【图书管理员】
    题解 P2036 【Perket】
    题解 CF837A 【Text Volume】
    题解 CF791A 【Bear and Big Brother】
    题解 CF747A 【Display Size】
    题解 P1332 【血色先锋队】
    题解 P2660 【zzc 种田】
    题解 P4470 【[BJWC2018]售票】
  • 原文地址:https://www.cnblogs.com/ruanian/p/11060227.html
Copyright © 2011-2022 走看看