@PostMapping("/login")
public String login( Member inputMember,
Model model,
RedirectAttributes ra,
HttpServletResponse resp,
HttpServletRequest req,
@RequestParam(value="saveId", required=false) String saveId ) {
logger.info("로그인 기능 수행됨");
Member loginMember = service.login(inputMember);
if(loginMember != null) {
model.addAttribute("loginMember", loginMember);
Cookie cookie = new Cookie("saveId", loginMember.getMemberEmail());
if(saveId != null) {
cookie.setMaxAge(60 * 60 * 24 * 365);
} else {
cookie.setMaxAge(0);
}
cookie.setPath(req.getContextPath());
resp.addCookie(cookie);
} else {
ra.addFlashAttribute("message", "아이디 또는 비밀번호가 일치하지 않습니다.");
}
return "redirect:/";
}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!--
* http://localhost:8080/comm
* http://localhost:8080/comm/main 주소로 요청 위임
-> forward 이기 때문에 출력되는 주소는 http://localhost:8080/comm 유지
-->
<jsp:forward page="main" />
package edu.kh.comm.main.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MainController {
@RequestMapping("/main")
public String mainForward() {
return "common/main";
}
}