caching images served by servlet

后端 未结 4 1359
臣服心动
臣服心动 2020-12-03 01:44

I\'m serving up images from my servlet. The response content type is image/jpeg. I find that images requested from my servlet are not cached. How do I get them to be cached

4条回答
  •  情歌与酒
    2020-12-03 02:49

    For example, if you want to cache them for 1 month:

    Calendar inOneMonth = Calendar.getInstance();
    inOneMonth.add(Calendar.MONTH, 1);
    
    response.setDateHeader("Expires", inOneMonth.getTimeInMillis());
    

    (this is in a Filter that handles the *.jpg pattern, for example)

    But images should be cached by default - check your filters and configurations to see if something isn't setting the cache parameters incorrectly.

提交回复
热议问题