Refresh image with a new one at the same url

后端 未结 19 3321
南旧
南旧 2020-11-21 22:00

I am accessing a link on my site that will provide a new image each time it is accessed.

The issue I am running into is that if I try to load the image in the backgr

19条回答
  •  情歌与酒
    2020-11-21 22:43

    I solved this problem by sending the data back through a servlet.

    response.setContentType("image/png");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache, must-revalidate");
    response.setDateHeader("Expires", 0);
    
    BufferedImage img = ImageIO.read(new File(imageFileName));
    
    ImageIO.write(img, "png", response.getOutputStream());
    

    Then from the page you just give it the servlet with some params to grab the correct image file.

    
    

提交回复
热议问题