下载图片,excel等

@RequestMapping(value = "indexoutput")

    public void indexOutPut(HttpServletResponse response) throws ServiceException, IOException {

        response.addHeader("Content-Disposition", "attachment; filename=output" + System.currentTimeMillis() + ".png");

        File file = new File("C:\\Users\\Administrator\\Desktop\\ddd\\48.png");

        FileInputStream fis = new FileInputStream(file);

        byte[] bs = new byte[1024];

        while(fis.read(bs)!=-1){

            response.getOutputStream().write(bs);

        }

        response.flushBuffer();

        fis.close();

    }

修改filename为图片或excel等其他后缀即可下载

猜你喜欢

转载自wisfly.iteye.com/blog/2227689