Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpServletRequest.getSession(false): When does it return null?

I'd like to know when to expect a "null" when calling HttpServletRequest.getSession(false)

Also: Are there good tutorials on HttpSession? I'd like to get details like: when to invalidate()? what are the consequences? do I need to check if the returned HttpSession is valid? ... <== Answer that in a comment please.

like image 609
AndrewBourgeois Avatar asked Oct 08 '22 17:10

AndrewBourgeois


1 Answers

You should practically never expect a null value. As the documentation says, if there is no active session for a request (usually, you would check for that in the filter chain of a request), a session will be created. If you get a null value from this, I'd wager that there is a problem in the underlying OS: Not enough memory to spawn a session would come to mind.

like image 137
0xCAFEBABE Avatar answered Oct 10 '22 08:10

0xCAFEBABE