注销在 spring mvc 中不起作用

logout not working in spring mvc

登录我的应用程序后,我无法注销

@SessionAttributes("email")
public class HomeController {

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

        return "home";
    }

}

我的 home.jsp 页面,

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

点击注销按钮后,电子邮件变量显示...

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

如果您想重置电子邮件会话属性,请尝试此操作。

拜托,你能检查一下 classsession 对象中是否有任何东西,或者它是否为空?否则试试 request.getSession().invalidate(); 这应该有效!

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