缓存servlet提供的图像 [英] caching images served by servlet

查看:154
本文介绍了缓存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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆