Why session is not null after session.invalidate() in JAVA?

前端 未结 3 1003
南方客
南方客 2020-12-16 01:01

I am facing very strange problem while developing JavaEE WEB Application.

Even after invalidating the HttpSession using session.invalidate();

3条回答
  •  臣服心动
    2020-12-16 01:16

    The invalidate method does the following (from API):

    Invalidates this session then unbinds any objects bound to it.

    It says nothing about the HttpSession-object itself, but invalidates the session's variables. If you call a method of a class, it is impossible for the object to be null after that method call. If your session should be null afterwards, the method must include a line that looks something like: this = null; which would not be possible. Throwing an exception for an invalidated session is the prefered way to do it.

提交回复
热议问题