代码改变世界

Controller 返回图片请求

2017-12-28 10:21  如是我所闻  阅读(2240)  评论(0编辑  收藏  举报

jsp代码

    <img src="getBiImg" width="100%"/> //getBiImg是请求url

 

controller代码

    @RequestMapping(value="/getBiImg")
    public void getBiImg(HttpServletRequest request, HttpServletResponse response) throws IOException {
         response.setHeader("Pragma", "no-cache");  
            response.setHeader("Cache-Control", "no-cache");  
            response.setDateHeader("Expires", 0);  
            response.setContentType("image/jpeg");  
            File file=biReportService.getImgMark();//获取图片这个文件
            InputStream is=new FileInputStream(file);
            BufferedImage bi=ImageIO.read(is);
            ImageIO.write(bi, "JPEG", response.getOutputStream());
    }