如何删除jsf 2缓存? [英] How to remove jsf 2 cache?

查看:138
本文介绍了如何删除jsf 2缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有jsf网页,多数民众赞成在前几页中进行一些Strings查询.

i have jsf webpage , thats takes some Strings query from previous pages .

我的问题是,该主页似乎具有缓存的值,没有任何变化.即使我将这些值更改为null,它也应该获得null页,但它的值变得更旧.

my problem is this main page seems to have cached values , no change Even i changed those values to null , it's supposed to get null page but it getting older value .

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

so my Q is : how to make my Main jsf page getting reloaded or cache deleted every time i calling it or i press F button ?

我尝试过我的JSF示例代码:

My JSF sample code i have try :

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

}

推荐答案

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

The <meta http-equiv> tags are only used when the HTML file in question is been opened from a non-HTTP resource such as local disk file system (via file:// URI) and not when the HTML file in question is been opened from a real HTTP resource (via http:// URI). Instead, the real HTTP response headers as set via HttpServletResponse#setHeader() are been used.

因此,对于您的JSF页面,仅当在Webbrowser中打开JSF页面且最终用户通过Webbrowser的 File> Save As 将其HTML输出保存到HTML文件时,才会解析这些标签. em>,然后通过在文件资源管理器中双击保存的文件来重新打开.

So, in case of your JSF page, those tags are only interpreted when the JSF page is been opened in webbrowser and its HTML output is by the enduser saved to a HTML file via webbrowser's File > Save As and then reopened by doubleclicking the saved file in file explorer.

因此,您的具体问题可能是由于忽略的那些标签引起的.您需要直接在HTTP响应上而不是在HTML头中设置这些标头.您可以为此使用servlet过滤器.在下面的另请参阅"链接中,您可以找到一个具体的代码示例.

So, your concrete problem is likely caused because those <meta http-equiv> tags are ignored. You need to set those headers straight on the HTTP response instead of in the HTML head. You can use a servlet filter for that. In the following "See also" links you can find a concrete code example.

  • How to control web page caching, across all browsers?
  • Avoid back button on JSF web application

无关与具体问题无关,您的JDBC代码正在泄漏资源.这是一个严重的问题.您的JDBC将在一段时间后停止运行. 别忘了也要修复此问题.

Unrelated to the concrete problem, your JDBC code is leaking resources. This is a severe problem. Your JDBC will stop functioning after some time. Don't forget to fix that as well.

这篇关于如何删除jsf 2缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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