Session is invalidated
immediately once you call .invalidate
method
From docs ,
invalidate
void invalidate()
Invalidates this session then unbinds any objects bound to it.
From your question
I didn't understood why these happen even if i invalidate that session.
but when i refresh that page it will again hit the login page.
It is because the page is loaded from the browser cache , even if it goes to the previous page you can't send any request from the page loaded
Update
Check this How to clear browser cache using java
Hope this helps!!