How to maintain session for a user until user is logged-in in spring mvc

How to maintain session for a user until user is logged-in in spring mvc

Using the controller to log in your user you could create and store your session there…

    public ModelAndView yourMethod(HttpSession session){

    session.setAttribute(user, 1); 
    return new ModelAndView(home);

}

If you want to retrieve it you can do it like this

Long userId = (Long) session.getAttribute(user);

Spring will maintain the session for you,

How to maintain session for a user until user is logged-in in spring mvc

Leave a Reply

Your email address will not be published. Required fields are marked *