3

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

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 .

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 ?

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

}

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
hesham
  • 143
  • 2
  • 2
  • 8

1 Answers1

7

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.

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.

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.

See also:


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.

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452