When I'm clicking logout button I want the browser cache to be cleared.
I'm trying to clear the browser cache, using the following code:
if(uri.equals("/SciArchive/logout.sci"))
{
HttpSession session=req.getSession(false);
res.setHeader("Cache-Control","no-cache");
res.setHeader("Cache-Control","no-store");
res.setDateHeader("Expires", 0);
res.setHeader("Pragma","no-cache");
if(session!=null)
{
session.invalidate();
rd=req.getRequestDispatcher("/home.jsp");
}
rd.forward(req,res);
return;
}
When back button is pressed in browser window after logout, I need the browser not showing the previous page.
When I'm clicking back button it shows the previous page, after clicking forward button in browser window it shows document expired
.
Please give me suggestions to clear this error!
You cannot clear the cache, but you can ask that your pages will not be cached. This means that you must do so for every page in your session (else the back-button will keep working, and your logout page is the only page not cached).
See also: How to control cache in JSP page?:
httpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. httpResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0. httpResponse.setDateHeader("Expires", 0); // Proxies.
edit: Apparently it is possible to clear the cache programmatically using javascript and a refresh, but I doubt that this is what you are looking for: How to programmatically empty browser cache?