Interceptor 예시:
if (session == null || session.getAttribute("loginUser") == null) {
request.getSession(true).setAttribute("sessionExpiredMsg", "세션이 만료되었습니다.");
response.sendRedirect("/login");
return false;
}
Login Controller 예시:
String msg = (String) session.getAttribute("sessionExpiredMsg");
if (msg != null) {
model.addAttribute("message", msg);
session.removeAttribute("sessionExpiredMsg");
}
해결법: 세션이 원래 있었는지 확인하는 조건 사용
boolean isSessionExpired =
request.isRequestedSessionIdFromCookie() &&
!request.isRequestedSessionIdValid();
→ 쿠키로 세션 ID를 보냈지만, 현재 세션은 무효
→ 진짜 "세션이 만료된 경우"만 메시지 전달 가능
메서드 | 설명 |
---|---|
getSession(true) 또는 기본 | 세션이 없으면 새로 생성 |
getSession(false) | 세션이 없으면 null 반환 (생성 안 함) |
→ 로그인 검사 같은 데서 불필요한 세션 생성을 방지하기 위해 사용
네. 반드시 지워야 함.
안 지우면 로그인 성공 후에도 계속 메시지가 남아있는 문제가 생김
session.removeAttribute("sessionExpiredMsg");
부모창:
function setPopupValue(val) {
$('#inputField').val(val);
}
팝업창:
window.opener.setPopupValue('맹구');
window.close();
if (window.opener && !window.opener.closed) {
const parentUrl = window.opener.location.href;
if (!parentUrl.includes('기대했던주소')) {
alert('부모창이 다른 페이지로 이동했네요!');
}
}