aspose file tools*
The moose likes JSP and the fly likes Making a page expire Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Making a page expire" Watch "Making a page expire" New topic
Author

Making a page expire

Jim Carey
Greenhorn

Joined: Nov 28, 2005
Posts: 10
I would like the page to expire when the back button is pressed so the message "Warning: Page has Expired etc" appears. I have found some suggestions in this forum and applied them, their not working for me, so I must be doing something wrong. I have tried the following response header combinations"

<% response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("max-age", 0);
response.setDateHeader("Expires", 0);%>


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


<%response.setHeader("Cache-Control","no-cache");
response.setHeader("Expires", "0");
response.setHeader("Pragma", "No-cache");
response.addHeader("Cache-control", "no-store");
response.addHeader("Cache-control", "max-age=0"); %>

I am new to JSPs & servlets, any help you can provide is greatly appreciated. Thanks in advance.

Sincerely
Jim Carey
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

"nocljhc",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jim Carey
Greenhorn

Joined: Nov 28, 2005
Posts: 10
Sorry about that, correction made.
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

I would like the page to expire when the back button is pressed


Controlling browser back button from server code is not possible. You got to use sessions(after proper authentication)along with response header to prevent restricted resources from being accessed by un-authenticated users.

[ December 09, 2005: Message edited by: Vishnu Prakash ]
[ December 09, 2005: Message edited by: Vishnu Prakash ]

Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
You can use those response header in order to tell the browser that please dont cache the page. But it might not work with all browsers. I guess it doesn't work with IE.

Otherwise, if back button just work like a new request, then you can do as Vishnu already said that you need to use session for this. After a successful login you can put the user bean into session and then check for that in session if found then OK otherwise redirect to login page.

Thanks.
Jim Carey
Greenhorn

Joined: Nov 28, 2005
Posts: 10
Thanks for replying.
I understand that I can create a session object to track the users activity and can redirect them when they reach a stale page. However I would like to pursue the Page expired message when the user moves back to a stale page. Is there some other technology involved beyond setting response headers in a JSP or Servlet that cause this to occur? I am running IE 6.0, I see the "page expired" message frequently on my machine. I am doing this for a school project.

Thanks in advance
Sincerely
Jim Carey
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Making a page expire