簡體   English   中英

如何在注銷監聽器中獲取HTTP會話ID?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM