如何删除jsf 2缓存?

时间:2013-09-14 09:48:05

标签: jsf jsf-2 primefaces browser-cache

我有jsf网页,这需要从之前的页面查询一些字符串。

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

所以我的问题是:每次调用时我如何让我的主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 class:

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);

}

1 个答案:

答案 0 :(得分:7)

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

因此,在您的JSF页面的情况下,这些标记仅在Web浏览器中打开JSF页面时解释,并且其HTML输出由最终用户通过webbrowser的文件&gt;保存到HTML文件。另存为,然后双击文件资源管理器中保存的文件重新打开。

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

另见:


对于具体问题

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