Java:Why http session is not destroyed when tab or browser is closed?

后端 未结 8 1700
-上瘾入骨i
-上瘾入骨i 2020-12-06 00:54

I have the following implementation of HttpSessionlistener

public class SessionListener implements HttpSessionAttributeListener, HttpSessionListener {


publ         


        
相关标签:
8条回答
  • 2020-12-06 01:33

    Session objects live in the server and are controlled by the server. Only the server can create or destroy sessions. So if the client is closed the session lives until it expires. The client can only suggest to the server that it can destroy some session. This request must be explicit somehow. Hence, when you close a browser window, there's no implicit request to the server informing that it must destroy a given session.

    0 讨论(0)
  • 2020-12-06 01:33

    As Eric mentioned the unload event on the browser can call a javascript function, which in turn can access an url through a servlet that logs you out. You need not wait for the actual response from the servlet.

    The web browser interacts with the server through the http protocol and that is stateless.

    0 讨论(0)
提交回复
热议问题