'clearing cache is not working in my jsp and servlet pages,when i logout and press back button it is still showing previous page.what should i do?

<%
HttpServletResponse httpResponse = (HttpServletResponse) response;
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.
%

i am using this code

this is login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <div style="text-align: center">
        <h1>admin login</h1>
        <form action="/UserOne" method="get">
            <label for="id">Id</label> <input name="id"/> 
            <label  for="name">Name</label> <input type="text" name="name" />
            <button type="submit">Login</button>
        </form>
        
    </div>
</body>
</html>

this is admin.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.PrintWriter"%>
<!DOCTYPE html>
<html>
<head>
<style>
body {
    background-image: url(/images/admin.jpg);
    background-repeat: repeat;
    background-size: 640px 640px;
}
</style>
</head>
<body>

    <%
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    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.
    %>
    <a href="/userone">get all users</a>
    <h3>view user</h3>

    getMobileInfo
    <a href="/indexone">get all mobile details</a>


    <form action="/LogoutServlet" method="get">
        <input type="submit" value="logout">
    </form>

</body>
</html>

this is admin.jsp how to delete cache memory,so that when i press previos button it does not show any data,how to clear cache memory in browser ,jsp and servlets,i have added this code in many jsp and servlet page,still it does not working,what should i have to add?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source