header.jsp
<c:choose>
<c:when test="${empty principal}"> // -> 로그아웃상태
<li class="nav-item"><a class="nav-link" href="${cp}/user?cmd=joinForm">회원가입</a></li>
<li class="nav-item"><a class="nav-link" href="${cp}/user?cmd=loginForm">로그인</a></li>
</c:when>
<c:otherwise> // -> 로그인 상태
<li class="nav-item"><a class="nav-link" href="${cp}/board?cmd=saveForm">글쓰기</a></li>
<li class="nav-item"><a class="nav-link" href="${cp}/user?cmd=updateForm">회원정보변경</a></li>
<li class="nav-item"><a class="nav-link" href="**${cp}/user?cmd=logout">로그아웃**</a></li>
</c:otherwise>
</c:choose>
UserController.java
else if(cmd.equals("logout")) {
return new LogoutAction();
}
LogoutAction.java
public class LogoutAction implements Action{
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
session.invalidate(); // -> 세션무효화 코드라고 말해줬찌
response.sendRedirect("/blog");
}
}
principal 이 empty 이기 때문에
header.jsp
의 아래 부분이 실행된 것이야
<c:when test="${empty principal}"> // -> 로그아웃상태
<li class="nav-item"><a class="nav-link" href="${cp}/user?cmd=joinForm">회원가입</a></li>
<li class="nav-item"><a class="nav-link" href="${cp}/user?cmd=loginForm">로그인</a></li>
</c:when>