缓存servlet提供的图像 [英] caching images served by servlet
问题描述
我正在从我的servlet提供图像。响应内容类型是image / jpeg。我发现从我的servlet请求的图像没有被缓存。如何通过文件图像请求缓存它们?我尝试设置Cache-Control:public但无济于事。
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 like file image requests normally are? I tried setting Cache-Control: public but to no avail.
推荐答案
Ok ..看起来默认的头字段应该启用缓存。我在另一个论坛找到了解决方案。显然,您需要在响应中明确设置内容长度。不知道为什么。我以为HttpServletResponse会为我们做那件事。无论如何,它就像一个魅力,图像得到很好的缓存。
Ok.. looks like the default header fields should enable caching. I found a solution in another forum. Apparently, you need to explicitly set a content-length in the response. Wonder why though. I thought the HttpServletResponse would do that for us. Anyway, it worked like a charm and the image is getting cached nicely.
这篇关于缓存servlet提供的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!