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

查看:24
本文介绍了缓存由 servlet 提供的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从我的 servlet 提供图像.响应内容类型是图像/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.

推荐答案

好吧.. 看起来默认头字段应该启用缓存.我在另一个论坛找到了解决方案.显然,您需要在响应中明确设置内容长度.不知道为什么.我认为 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天全站免登陆