Java 如何在登录处理程序中检索在successhandler中设置的会话值

Java 如何在登录处理程序中检索在successhandler中设置的会话值,java,session,spring-security,Java,Session,Spring Security,我在LoginSuccessHandler(扩展CustomAuthenticationSuccessHandler)中设置了一个会话属性,如 我想在LogoutSuccessHandler(扩展SimpleRullogoutSuccessHandler)中检索相同的值 public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authenticatio

我在LoginSuccessHandler(扩展CustomAuthenticationSuccessHandler)中设置了一个会话属性,如

我想在LogoutSuccessHandler(扩展SimpleRullogoutSuccessHandler)中检索相同的值

public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {

HttpSession session = request.getSession();
session.getAttribute("TICKET");
    }
我得到空值。如何在登录处理程序中检索我在successhandler中设置的会话值。

我认为当会话被破坏时,将触发“onLogutSuccess”方法。因此,在会话中找不到任何值或参数。
您对request.getSession()所做的是创建一个新会话,该会话将为属性返回null,因为该会话不存在该属性。

会话无效后,spring安全性将调用
注销成功url
,因此您将无法在此处找到会话

所以解决方法是从注销链接调用注销url模式 用这个

@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout(ModelMap model, HttpSession session) {
    //** do some thing **//
    return "redirect:/j_spring_security_logout";

}

你在使用spring安全是的,我在使用spring安全谢谢你的回答John
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout(ModelMap model, HttpSession session) {
    //** do some thing **//
    return "redirect:/j_spring_security_logout";

}