request.getSession(true)和request.getSession(false)的区别

request.getSession(true)和request.getSession(false)的区别

 
request.getSession(true):若存在会话则返回该会话,否则新建一个会话。
request.getSession(false):若存在会话则返回该会话,否则返回NULL

当向Session中存取登录信息时,一般建议:HttpSession session =request.getSession();

当从Session中获取登录信息时,一般建议:HttpSession session =request.getSession(false);

原文地址:https://www.cnblogs.com/whx20100101/p/9862295.html