[英]How to get http session id in logout listener?
我的监听器监听用户注销。 我需要知道此侦听器的会话ID。
public class MyLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {
@Autowired
private UserService userService;
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
RequestContextHolder.currentRequestAttributes().getSessionId();
}
}
它产生
找不到线程绑定的请求:您是在实际的Web请求之外引用请求属性,还是在原始接收线程之外处理请求? 如果您实际上是在Web请求中操作并且仍然收到此消息,则您的代码可能在DispatcherServlet / DispatcherPortlet之外运行:在这种情况下,请使用RequestContextListener或RequestContextFilter公开当前请求。
在我的具体情况下如何解决?
见这在计算器上。 将以下内容添加到您的web.xml
:
<web-app>
...
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
...
</web-app>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.