@GetMapping(...)
public String method(HttpServletRequest request){WebUtils.setSessionAttribute(request,"이름",값);WebUtils.getSessionAttribute(request,"이름");public String mehtod( HttpServletResponse response ){Cookie cookie = new Cookie("이름","값");cookie.setMaxAge( 초 );response.addCookie( cookie )annotation사용 (method의 매개변수 앞에 선언)
사용법)
@CookieValue(value="쿠키의이름", defaultValue="쿠키가 없을 때 설정될 값")
@GetMapping(...)
public String method(@CookieValue(value="이름",defaultValue="기본값") String name)
public String method( HttpServletResponse request){String value=WebUtils.getCookie(request,"이름").getValue();

@RequestMapping(value="요청URL",method=GET,produces="application/json;charset=UTF-8")Controller method에서 예외가 발생되고, throws로 예외가 던져지면 DispatcherServlet이 예외를 잡아서 처리한다.
Controller안에서 다른 method의 예외를 처리할 수 있는 method를 정의할 때 사용
사용법 )
같은 종류의 예외를 여러 method에서 발생하더라도 하나의 @ExceptionHandler를 정의 method로 통합되어 처리된다.
@Controller
public class TestController(){
//요청 method가 달라도 하나의 처리 method로 통합되어 예외가 처리된다.
@GetMapping(...)
public String methodA() throws SQLException{
예외발생예상코드
}//methodA
@GetMapping(...)
public String methodB() throws SQLException{
예외발생예상코드
}//methodB
@ExceptionHandler(SQLException.class)
//@ExceptionHandler에 정의된 예외만 잡고 다른예외는 잡지않는다.
//ExceptionHandler에 정의된 예외는 DispatcherServlet에서 잡지 않는다.
public ModelAndView exceptionMethod(SQLException se){
예외처리코드
ModelAndView mav = new ModelAndView();
//ModelAndView는 예외처리할때 아니면 잘 사용하지 않는다.
mav.setViewName("view명");
mav.addObject("이름",view페이지 전달할 예외의 정보);
return mav;
}
}