0

What makes the HttpSession instance expire as after time-out also when checked

 if(session!=null){

        System.out.println("The instance is not null");
        }else{
        System.out.println("The instance is null");
        }

each time the if-block is executed.

Prasad Kharkar
  • 13,410
  • 5
  • 37
  • 56
wadjikars
  • 21
  • 1
  • 1
  • 3

2 Answers2

0
  • For expiring the session, use session.invalidate(). This will ensure that your session is expired.
  • Even if session is invalidated, it doesn't necessarily mean it is null
Prasad Kharkar
  • 13,410
  • 5
  • 37
  • 56
0

If you use HttpServletRequest.getSession(false), then a HttpSession object does not get created, if it is invalid.

In that case, session can be null.

Moritz Petersen
  • 12,902
  • 3
  • 38
  • 45