-1

I have made a dynamic Web application using eclipse. I have a static html page (login page) that leads to the application using servlets. Then if you logout and then press the browser back button it let's you go back. How do I prevent this from happening? I think it's called session management

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
KwstasMost
  • 130
  • 1
  • 10

1 Answers1

1

This is the required code to manage session using cookies

if(userID.equals(user) && password.equals(pwd)){
            Cookie loginCookie = new Cookie("user",user);
            //setting cookie to expiry in 30 mins
            loginCookie.setMaxAge(30*60);
            response.addCookie(loginCookie);
            response.sendRedirect("LoginSuccess.jsp");
        }else{
            RequestDispatcher rd = getServletContext().getRequestDispatcher("/login.html");
            PrintWriter out= response.getWriter();
            out.println("<font color=red>Either user name or password is wrong.</font>");
            rd.include(request, response);
        }

Use it according to your web application project.

Ketan G
  • 507
  • 1
  • 5
  • 21