작성
·
267
0
안녕하세요. 웹 브라우저와 세션에 대해 질문을 드리려 합니다.
@PostMapping("/login")
public String loginV3(@Valid @ModelAttribute LoginForm form, BindingResult bindingResult, HttpServletRequest request) {
if (bindingResult.hasErrors()) {
return "login/loginForm";
}
Member loginMember = loginService.login(form.getLoginId(), form.getPassword());
if (loginMember == null) {
bindingResult.reject("loginFail", "아이디 또는 비밀번호가 맞지 않습니다.");
return "login/loginForm";
}
//로그인 성공 처리
//세션이 있으면 있는 세션 반환, 없으면 신규 세션을 생성
HttpSession session = request.getSession();
//세션에 로그인 회원 정보 보관
session.setAttribute(SessionConst.LOGIN_MEMBER, loginMember);
return "redirect:/";
}
session.setAttribute(SessionConst.LOGIN_MEMBER, loginMember);를 통해 세션에 멤버 객체를 저장하였습니다.
그리고 아래 코드에서 세션에 저장된 정보를 조회하죠. 이 말은 웹 브라우저에서 세션 아이디를 전송해 주었다는 것인데, Thymeleaf에서는 세션 아이디를 쿠키에 넣어서 전송해 주는 코드가 없는 것 같은데, 어떻게 웹 브라우저에서 세션 아이디가 전송된 것인가요?
@GetMapping("/")
public String homeLoginV3Spring(
@SessionAttribute(name = SessionConst.LOGIN_MEMBER, required = false) Member loginMember, Model model) {
//세션에 회원 데이터가 없으면 home
if (loginMember == null) {
return "home";
}
//세션이 유지되면 로그인으로 이동
model.addAttribute("member", loginMember);
return "loginHome";
}
읽어주셔서 감사합니다.
답변 감사드립니다.