Jan 27

Some times you need to tell the browser not to cache some pages in your web application.

To achieve this we can use META tags that instruct the browser how you would like the page cached. As is too often the case the meta tags required can vary between browsers. The “Pragma” meta seems the most widely supported at the moment:

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

Using the following though will give you better browser coverage:

<META HTTP-EQUIV="Cache-Control" CONTENT="max-age=0">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META http-equiv="expires" content="0">
<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

written by objects \\ tags: , ,

Jan 02

The Properties class has a store() method for saving a set of properties to a stream. There are lots of examples on the web that show how to use store() but unfortunately the majority of them fail to close the stream which is a bit misleading for new developers. Closing the stream is the responsibility of the caller (as mentioned in the javadoc), and failure to do it can result in the properties not being written to their ultimate destination.

Here’s an example showing how to write the properties to a file (including closing the stream).

Properties prop = new Properties();
OutputStream out = new FileOutputStream("my.properties"); 
try {
     prop.setProperty("abc", "123");
     prop.store(out, null);
} catch (IOException ex) {
     ex.printStackTrace();
} finally {
     out.close();
}

written by objects \\ tags: , , ,