Prevent HTML and JSP pages from being cached and re-fetched from the web server

Prevent HTML and JSP pages from being cached and re-fetched from the web server
After the user logs out, if the back button on the browser is clicked, the web application will not be able to properly protect the protected page - after the Session is destroyed (the user logs out), the protected JSP page is displayed again in the browser.
However, if the user clicks any link on the return page, the web application will jump to the login page and prompt that the session has ended. Please log in.

The root of the above problem is that most browsers have a back button.

When you click the back button, by default the browser does not re-fetch the page from the web server, but instead loads the page from the browser cache.

Java-based Web applications do not limit this function, and this problem also exists in Web applications based on PHP, ASP and .NET.
Fortunately, the HTTP headers "Expires" and "Cache-Control" provide a mechanism for application servers to control caching on browsers and proxy servers.

The HTTP header Expires tells the proxy server when its cached page will expire.
The newly defined header information Cache-Control in the HTTP1.1 specification can notify the browser not to cache any pages.

When you click the back button, the browser re-accesses the server to fetch the page.

Here is the basic method of using Cache-Control:
1) no-cache: Force cache to get new pages from the server
2) no-store: Do not store any pages in the cache under any circumstances

To be on the safe side, it is best to add some settings to both the html page and the jsp

For HTML pages, add:

Copy code
The code is as follows:

<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">

For JSP pages, add:

Copy code
The code is as follows:

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

That's it.

<<:  Detailed explanation of AWS free server application and network proxy setup tutorial

>>:  Detailed explanation of the writing order and execution order of Mysql series SQL query statements

Recommend

How to Apply for Web Design Jobs

<br />Hello everyone! It’s my honor to chat ...

Use HTML and CSS to create your own warm man "Dabai"

The final result is like this, isn’t it cute… PS:...

JavaScript Reflection Learning Tips

Table of contents 1. Introduction 2. Interface 3....

Pure js to achieve typewriter effect

This article example shares the specific code of ...

Running PostgreSQL in Docker and recommending several connection tools

1 Introduction PostgreSQL is a free software obje...

Fixed a bug caused by scrollbar occupying space

background This bug was caused by滾動條占據空間. I check...

How to use shell scripts in node

background During development, we may need some s...

Use and analysis of Mysql Explain command

The mysql explain command is used to show how MyS...

Detailed explanation of Angular parent-child component communication

Table of contents Overview 1. Overview of input a...

Two-hour introductory Docker tutorial

Table of contents 1.0 Introduction 2.0 Docker Ins...

Common operation commands of MySQL in Linux system

Serve: # chkconfig --list List all system service...

How to configure VMware virtual machine NAT mode

This article describes the VMware virtual machine...

5 tips for writing CSS to make your style more standardized

1. Arrange CSS in alphabetical order Not in alphab...