简体   繁体   中英

logout not working in spring mvc

After logging in to my application, I can't able to log out

@SessionAttributes("email")
public class HomeController {

    @RequestMapping(value = {"/logout"}, method = RequestMethod.GET)
    public String logout(HttpSession session, HttpServletRequest request, HttpServletResponse response){
        session.invalidate();

        return "home";
    }

}

My home.jsp page,

 <p>${email}</p>
<a href="logout">Logout</a>

After clicked log out button still, email variable showing...

@RequestMapping(value = {"/logout"}, method = RequestMethod.GET)
public String logout(HttpServletRequest request, SessionStatus session){
    session.setComplete();
    request.getSession().invalidate();
    return "login";
}

Try this if you want to reset email session attribute.

Please, can you check if there's anything in the session object of that class or is it null? else try request.getSession().invalidate(); This should work!

@RequestMapping(value = {"/logout"}, method = RequestMethod.GET)
public String logout(HttpServletRequest request, SessionStatus session){
    session.setComplete();
    request.getSession().invalidate();
    return "login";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM