在JSF页面中缓存图片 [英] caching pictures in JSF page

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

问题描述

正在从事一些JSF 2.0项目.具有为新用户/现有用户添加图片的表格.在不刷新页面(* .xhtml)的情况下看不到新添加的图片.我试图放常规:

Working on some JSF 2.0 project. Have form for adding picture for new/existing user. Can't see a new added picture without refreshing the page (*.xhtml). I tried to put regular:

<meta http-equiv="pragma" content="no-cache"> 
<meta http-equiv="cache-control" content="no-cache"> 
<meta http-equiv="expires" content="0">  

但这没有帮助.

如何禁用页面缓存?

推荐答案

通过HTTP提供网页时,忽略 HTML <meta http-equiv>标签.仅当最终用户将页面保存到本地磁盘文件系统,然后通过file:// URL从中打开页面时,才会解释<meta http-equiv>标记.

The HTML <meta http-equiv> tags are ignored when the page is been served over HTTP. The <meta http-equiv> tags are only interpreted when the page is by the enduser been saved to the local disk file system and then opened from it by a file:// URL.

您需要在 real HTTP响应上设置这些标头.最简单的方法是使用 servlet过滤器

You need to set those headers on the real HTTP response instead. Easiest way is to use a servlet filter which basically does

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(request, response);

(请注意,您原来的Cache-Control标头不完整,上面的示例是正确的用法)

(note that your original Cache-Control header was incomplete, the above example is the proper usage)

您可以将映射到特定页面的URL模式上,但也可以考虑将其映射到JSF生成的所有动态页面上.

You could map the on the URL pattern of the specific page, but you could also consider to map it on all dynamic pages generated by JSF.

这篇关于在JSF页面中缓存图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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