<<javaWeb王者归来>>上面写getSession()在session不存在的情况下会返回null,但是查看ServletAPI文档可以看到
依据api文档
HttpSession | getSession() Returns the current session associated with this request, or if the request does not have a session, creates one. |
HttpSession | getSession(boolean create) Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session. |
getSession()应该和getSession(true)等效的,肯定不会返回null
getSession(false)有可能返回null
但是还是有一点点的怀疑,打算以后以英文书籍为标准,很多中国作者都是苦鬼互相坑害的,或者只是为了显摆和挣钱,不好意思前几天写重了
本文探讨了JavaWeb中getSession()方法的行为,指出其在没有现有会话时将创建新的会话,而不是返回null。文章还对比了getSession()与getSession(false)的区别,并建议以官方文档作为权威来源。
2795

被折叠的 条评论
为什么被折叠?



