RSS

Disable browser caching for a specific JSP using HTML meta tag

23 Feb

Hi folks,

Recently i have faced one JSP page caching issue and sharing with you all, so that other people can not seek for the solution and not to waste their valuable time.
Here is the detailed post.

Issue details :

When i login in to the application and clicking on the home page link at the bottom in the application with out clicking on the logout button, it will navigate to the home page of the appliciation. There i have logout button while clicking on the logout button, it will logout properly. Without closing the browser and paste the application URL it is not asking the login page, instead it is directly navigating to the application without login page. So it’s a highly security issue i.e other customers can see the details of the previous customer. To resolve this issue, i have made the below code changes it worked fine.

<meta http-equiv=”cache-control” content=”max-age=0″ />
<meta http-equiv=”cache-control” content=”no-cache” />
<meta http-equiv=”expires” content=”Sat, 01 Sep 2001 00:00:00 GMT” />
<meta http-equiv=”pragma” content=”no-cache” />

Note: Normally developers will try putting the expires content value to “-1” , it won’t work. You have to assign timestamp value to make work it out.

Some Other Information:

It is possible to keep the browser from caching a JSP page response. The following hints added to the response header seem to prevent most modern
browsers from pulling pages out of cache when the same URL is “hit”:

<%
response.setHeader( “Pragma”, “no-cache” );
response.setHeader( “Cache-Control”, “no-cache” );
response.setDateHeader( “Expires”, 0 );
%>

The same effect can be achieved by using meta tags in the HTML header:

<meta http-equiv=”cache-control” content=”max-age=0″ />
<meta http-equiv=”cache-control” content=”no-cache” />
<meta http-equiv=”expires” content=”Sat, 01 Sep 2001 00:00:00 GMT” />
<meta http-equiv=”pragma” content=”no-cache” />

The Cache-Control header was added in HTTP 1.1, while the other two were also present in HTTP 1.0.

Happy Coding!

Have a nice day 🙂

Advertisements
 
Leave a comment

Posted by on February 23, 2013 in Uncategorized

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: