aspose file tools*
The moose likes Servlets and the fly likes How to control cached pages? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to control cached pages?" Watch "How to control cached pages?" New topic
Author

How to control cached pages?

Rui Ferns
Greenhorn

Joined: May 06, 2001
Posts: 24
Hi all,
My problem is,I want to know how to stop users from seeing previous pages by using the back button. Like if someone fills out form fields and then submits and leaves the PC and then another user comes along and hits the back button then they can see all the past users sensitive info in the form fields.
It seems the browser is retrieving the cached pages.How can I stop this from happening. I'd like to have it that if a person tried to hit the back button then they are taken to a warning page telling them that they can't view this page and give them a link to the start page.
I've tried various methods to solve this problem but none seem to work properly.
Could anyone tell me how to tell a jsp not to use the cached pages?
thanks
Rui
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

I use the pragma no-cache meta tag. It seems to work fine. From memory, I think the tag goes something like:
<html>
<head>
<meta param="pragma" value="no-cache">

I think
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Why would you use the meta tag if you can set the response headers directly?
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Expires", "0");
- Peter
Mark Simms
Ranch Hand

Joined: Jul 20, 2000
Posts: 36
<%
response.addHeader("Pragma", "NoCache");
response.addHeader("Cache-Control", "no-cache");
response.addDateHeader("Expires", 1);
%>
The official way is above......
be sure to warn users of the warning message they will get from their browsers....


Mark
Rui Ferns
Greenhorn

Joined: May 06, 2001
Posts: 24
Hi,
I tried that and it still isn't working.
I must be doing something wrong.
Where exactly should I put the code you gave?
Should it be in the page I want not to be cached?
So when the user presses the back button this page doesn't appear?
thanks
Rui
Originally posted by Mark Simms:
<%
response.addHeader("Pragma", "NoCache");
response.addHeader("Cache-Control", "no-cache");
response.addDateHeader("Expires", 1);
%>
The official way is above......
be sure to warn users of the warning message they will get from their browsers....

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to control cached pages?