HttpServletRequest.getSession(false):什么时候返回null? [英] HttpServletRequest.getSession(false): When does it return null?
问题描述
我想知道在调用 HttpServletRequest.getSession(false)
另外:是否有关于HttpSession的好教程?我想得到如下细节:何时无效()?有什么后果?我需要检查返回的HttpSession是否有效? ...< ==请在评论中回答。
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.
推荐答案
你几乎不应该期望一个空值。正如文档所述,如果请求没有活动会话(通常,您将在请求的过滤器链中检查该会话),则会创建会话。如果你从中得到一个空值,我会打赌底层操作系统有问题:没有足够的内存来产生一个会话会想到。
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.
这篇关于HttpServletRequest.getSession(false):什么时候返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!