gpt4 book ai didi

jsf - 如何删除 jsf 2 缓存?

转载 作者:行者123 更新时间:2023-12-01 09:59:14 24 4
gpt4 key购买 nike

我有 jsf 网页,那是从以前的页面中获取一些字符串查询。

我的问题是这个主页似乎有缓存值,没有变化即使我将这些值更改为空,它应该得到空页面但它得到旧值。

所以我的问题是:如何让我的主 jsf 页面在每次调用它或按下 F 按钮时都重新加载或删除缓存?

我尝试过的 JSF 示例代码:

     <h:head style="width: 200px; ">
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="edge, chrome=1" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
</f:facet>

Java 类:

String SID = FacesContext.getCurrentInstance().getExternalContext()
.getRequestParameterMap().get("SID");

String from = FacesContext.getCurrentInstance().getExternalContext()
.getRequestParameterMap().get("from");

String to = FacesContext.getCurrentInstance().getExternalContext()
.getRequestParameterMap().get("to");

String class_id = FacesContext.getCurrentInstance()
.getExternalContext().getRequestParameterMap().get("class_id");


if (SID==null) {
try {
Dbconnection NewConnect = new Dbconnection();
Connection con = NewConnect.MakeConnect();
Statement stmt = con.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT a.course_id, a.teacher_id, a.class_id, a.day_id, a.state, a.apssent_date, a.interval_id,s.student_id,s.first_name FROM student AS s INNER JOIN apsent AS a ON s.student_id = a.student_id where apssent_date between '"
+ from
+ "' and '"
+ to
+ "' and a.class_id = "
+ Integer.parseInt(class_id));


while (rs.next()) {

ids.add(rs.getInt(8));
names.add(rs.getString(9));
intervals.add(rs.getInt(7));
teachers.add(rs.getInt(2));
dates.add(rs.getString(6));
state.add(rs.getString(5));
}

} catch (Exception ex) {

System.out.println(ex);
}
}

System.out.println(SID + from + class_id + to);

if (class_id==null) {

try {
Dbconnection NewConnect = new Dbconnection();
Connection con = NewConnect.MakeConnect();
Statement stmt = con.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT a.course_id, a.teacher_id, a.class_id, a.day_id, a.state, a.apssent_date, a.interval_id,s.student_id,s.first_name FROM student AS s INNER JOIN apsent AS a ON s.student_id = a.student_id where apssent_date between '"
+ from
+ "' and '"
+ to
+ "' and s.student_id = " + SID);

while (rs.next()) {
// System.out.println(rs.getInt(1));

ids.add(rs.getInt(8));
names.add(rs.getString(9));
intervals.add(rs.getInt(7));
teachers.add(rs.getInt(2));
dates.add(rs.getString(6));
state.add(rs.getString(5));
}



} catch (Exception ex) {

System.out.println(ex);
}

}

carsSmall = new ArrayList<Car>();
populateRandomCars(carsSmall, ids.size(), ids, names,
intervals, teachers, dates, state);

最佳答案

<meta http-equiv>标记仅在从非 HTTP 资源(例如本地磁盘文件系统)打开相关 HTML 文件时使用(通过 file:// URI),而不是从真正的 HTTP 资源(通过http:// 网址)。相反,真正的 HTTP 响应 header 通过 HttpServletResponse#setHeader() 设置已被使用。

因此,对于您的 JSF 页面,仅当在 Web 浏览器中打开 JSF 页面并且其 HTML 输出由最终用户通过 Web 浏览器的 File > Save As 然后在文件资源管理器中双击保存的文件重新打开。

因此,您的具体问题很可能是因为那些 <meta http-equiv>标记被忽略。您需要直接在 HTTP 响应中设置这些 header ,而不是在 HTML header 中。您可以为此使用 servlet 过滤器。在以下“另请参阅”链接中,您可以找到具体的代码示例。

另见:


与具体问题无关,您的 JDBC 代码正在泄漏资源。这是一个严重的问题。您的 JDBC 将在一段时间后停止运行。 Don't forget to fix that as well .

关于jsf - 如何删除 jsf 2 缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18800460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com