Require login servlet to go to other pages

后端 未结 3 840
孤街浪徒
孤街浪徒 2021-01-29 08:40

There are a million examples on the web that shows how to create a basic Java Login Servlet, where the user has to enter a username and password which gets verified by some data

3条回答
  •  無奈伤痛
    2021-01-29 09:18

    when login is successful you can set a a value in session.setAttribute() and in all pages by using session.getAttribute() check if the value is present or not.If yes stay else go back to login page.

    example

    After login is successful do

        session.setAttribute("user","user");
    
    Now eac and every page check
    if(session.getAttribute("user")==null)
    {
    response.sendRedirect("loginpage");
    
    }
    else
    {
    
    //your codes
    }
    

提交回复
热议问题