javaweb中request.getSession(true)和request.getSession(false)的區別

request.getSession(true):若存在會話則返回該會話,否則新建一個會話。
request.getSession(false):若存在會話則返回該會話,否則返回NULL

當向Session中存取登錄信息時,一般建議:HttpSession session =request.getSession();

當從Session中獲取登錄信息時,一般建議:HttpSession session =request.getSession(false);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章