Overview
session , JSPL c 라이브러리 사용
- Controller
- jsp
1. Controller
/**
* 로그인 요청 처리
* @param SignInFormDto
*/
@PostMapping("/sign-in")
public String signInProc(SignInFormDto dto) {
httpSession.setAttribute("principal", user);
return "redirect:/...";
}
// 로그아웃 기능
@GetMapping("/logout")
public String logout() {
httpSession.invalidate(); // 세션 삭제
return "redirect:/...";
}
2. JSP - session 사용
JSPL C 라이브러리 사용
principal == 세션에 들어간 키값
<c:choose>
<c:when test="${principal != null}">
<li class="nav-item">
<a class="nav-link" href="/user/logout">로그아웃</a>
</li>
</c:when>
<c:otherwise>
<li class="nav-item">
<a class="nav-link" href="/user/sign-in">로그인</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/user/sign-up">회원가입</a>
</li>
</c:otherwise>
</c:choose>
'SpringBoot' 카테고리의 다른 글
Springboot - @RequestBody 와 @ModelAttribute 의 차이점 (0) | 2024.01.30 |
---|---|
URI 설계 - GET , POST, PUT , DELETE 와 Path Variable vs Query Parameter (0) | 2024.01.30 |
WebSocket - binary , text(참조) 타입 보내기 (1) | 2024.01.07 |
Springboot 2.x 버젼 - QueryDSL 설정 (0) | 2023.12.23 |
React , Springboot - 파일 한장 올리기 (0) | 2023.12.21 |