햄찌개

[JSP] getSession(), getSession(true), getSession(false) 차이점 본문

웹기반어플리케이션

[JSP] getSession(), getSession(true), getSession(false) 차이점

햄찌개 2020. 12. 18. 12:30

getSession(), getSession(true), getSession(false) 차이점

 

1. getSession(), getSession(true)

 - HttpSession이 존재하면 현재 HttpSession을 반환하고 존재하지 않으면 새로 세션을 생성합니다.

 

2. getSession(false)

 - HttpSession이 존재하면 현재 HttpSession을 반환하고 존재하지 않으면 새로 생성하지 않고 그냥 null을 반환합니다.

 

[참고] session.isNew() : 새로 생성된 세션이면 true를 리턴.

[참고] getSession(), getSession(true)는 null 체크없이 바로 getAttribute()를 사용해도 무방하지만, getSession(false)는 null을 리턴할수 있기 때문에 null체크를 해야 합니다.

 

 

 

사용 예)

 

HttpSession session = request.getSession(false);

if(session==null) {

logger.debug("[LOGIN CHECK] HTTP Session is NULL");

return false;

}

'웹기반어플리케이션' 카테고리의 다른 글

logging 프레임 워크 - log4j  (0) 2020.12.22
페이징 기법  (0) 2020.12.21
싱글톤  (0) 2020.12.18
iBatis  (0) 2020.12.17
3 Tier Architecture(3계층 구조)  (0) 2020.12.17