JSF and cache-control

本文探讨了IFrame缓存导致的数据不更新问题,并提出了三种解决方案:修改头部元信息、使用过滤器及清理Bean数据。这些方法能确保每次请求都获取最新的服务器数据。
进行的项目中遇到这样的问题,我的每一个连接都是连接一台服务器,点击一个连接时候刷新Iframe里页面配置一些参数,切换到另一个服务器连接的时候,Iframe里面列表依然显示着上一台服务器数据列表情况,bean数据没有清空。
在网上查了些资料,方法大概如下:
[b]方案一[/b]
在head里添加信息,好像不起作用,可能和bean范围有关,没有细究

<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache,must-revalidate" />
<meta http-equiv="expires" content="Wed,26 Feb 1997 08:21:57 GMT" />


[b]方案二[/b]
利用filter,很好的思路
One of the most annoying problems with building dynamic websites is how to control page cache.

The most used solution is to use a <meta content=”no-cache” http-equiv=”Pragma”/> tag inside the <HEAD> tag. Voilà, problem solved. Wrong! For two reasons:
1. It’s HTML, (most) proxy servers will still cache your pages since they don’t read HTML
2. The HTTP specification does not set any guidelines for Pragma response headers; instead, Pragma request headers are discussed.
Although a few caches may honor this header, the majority won’t, and it won’t have any effect.

However, true HTTP headers are almost always obeyed by any cache. With ADF Faces / JSF it is quite easy to gain control over your caching strategies with a phaselistener:


package nl.iteye.utils;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.servlet.http.HttpServletResponse;

public class NoCachePhaseListener implements PhaseListener {

public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}

public void afterPhase(PhaseEvent phaseEvent) {
}

public void beforePhase(PhaseEvent phaseEvent) {
FacesContext facesContext = phaseEvent.getFacesContext();
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.addHeader(“Pragma”, “no-cache”);
response.addHeader(“Cache-Control”, “no-cache”);
response.addHeader(“Cache-Control”, “no-store”);
response.addHeader(“Cache-Control”, “must-revalidate”);
response.addHeader(“Expires”, “Mon, 1 Jan 2006 05:00:00 GMT”);//in the past
}
}


And don’t forget to add the viewhandler to the faces-config.xml within the <lifecycle> tag : <phase-listener>nl.iteye.utils.NoCachePhaseListener</phase-listener> to make this magic work!

[b]方案三[/b]
每次连接之前,代码清除bean

TestBean tBean=((TestBean)FacesUtils.getManagedBean("testBean"));
tBean.tlists = null;
源码来自:https://pan.quark.cn/s/41b9d28f0d6d 在信息技术领域中,jQuery作为一个广受欢迎的JavaScript框架,显著简化了诸多操作,包括对HTML文档的遍历、事件的管理、动画的设计以及Ajax通信等。 本篇文档将深入阐释如何运用jQuery达成一个图片自动播放的功能,这种效果常用于网站的轮播展示或幻灯片演示,有助于优化用户与页面的互动,使网页呈现更加动态的视觉体验。 为了有效实施这一功能,首先需掌握jQuery的核心操作。 通过$符号作为接口,jQuery能够迅速选取DOM组件,例如$("#id")用于选取具有特定ID的元素,而$(".class")则能选取所有应用了某类class的元素。 在选定元素之后,可以执行多种行为,诸如事件监听、样式的变更、内容的更新以及动画的制作等。 关于“一个基于jQuery的图片自动播放功能”,首要任务是准备一组图片素材,这些素材将被整合至一个容器元素之中。 例如,可以构建一个div元素,将其宽度设定为单张图片的尺寸,再借助CSS实现溢出内容的隐藏,从而构建出水平滚动的初始框架。 ```html<div id="slider"> <img src="image1.jpg" alt="Image 1"> <img src="image2.jpg" alt="Image 2"> <!-- 更多图片内容... --></div>```接着,需要编写jQuery脚本以实现图片的自动切换。 这通常涉及到定时器的运用,以设定周期性间隔自动更换当前显示的图片。 通过使用`.fadeOut()`和`.fadeIn()`方法,能够实现图片间的平滑过渡,增强视觉效果。 ```javascript$(document).re...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值