-1

am using servlets to make a website of mine and having issues in releasing the session, pls check and find the error out:

login.java :
     ResultSet res=smt.executeQuery("Select * from admin where name='"+user+"' and password='"+password+"'");
    while(res.next())
    {
        String name=res.getString("name");
        String pwd=res.getString("password");
    if(category.equals("Admin"))
    {
        if(name.equals(user) && pwd.equals(password))
        {
                           ServletContext context=request.getServletContext();
                           context.setAttribute("name", name);
                            HttpSession session=request.getSession();
            session.setAttribute("name", name);
            RequestDispatcher view=request.getRequestDispatcher("welcome_admin.jsp");
            view.forward(request, response);
        }
        else
        {
            response.sendRedirect("index.jsp");
        }
    }

and the logout.jsp is :

   <body>
    <%

    session.removeAttribute("name");

    session.invalidate();



    %>
    <b>
        <%
        RequestDispatcher rd=request.getRequestDispatcher("index.jsp");
        rd.include(request, response);
        %>
    </b >
</body>

but the session isn't released and if i click the back button it again redirects me to pages!! someone pls help me out!!

rahul
  • 205
  • 3
  • 6
  • 12

2 Answers2

3

That is because your browser has cached that page, it is not coming from server any more, You need to instruct your browser not to cache pages by adding a Filter

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438
1

The problem is caching.

A workaround is to add this to your servlet:

Java servlet how to disable caching of page

// Set standard HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");

// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");
Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190