programming/web
[spring]ModelAndView, redirect, forward, session
힐무새
2017. 6. 7. 11:33
ModelAndView
model과 view에 대한 처리를 하나의 클래스에서 처리하고자 할때 활용됩니다.
redirect, forward
Controller 단에서 다른 controller를 호출해야 할 필요가 있을 때 처리합니다.
- ex) 수정이나 등록 후 메인 list로 화면 처리를 해야 할 경우
- ex) 수정이나 등록 후 메인 list로 화면 처리를 해야 할 경우
- redirect
- 입력하거나 넘겨주는 요청값이 필요 없을 때 - forward
- 요청값도 함께 넘겨주면서 controller단을 호출 할 때 활용 - 형식: 마지막 view단 호출 부분에
- return "redirect:/start.do" // "forward:/list.do"
xml 설정
컨테이너에 filter 조건으로 해당 정의된 클래스들을 자동 객체 등록 처리
context:component-scan
1) base-package : 대상 패키지 선언
context:include-filter: filter 기준으로 설정하는 내용
1) type : filter 대상에 대한 type ex) annotation
2) expression : 실제 쓰이는 클래스
ex) Controller, Service, Repository
context:exclude-filter: filter 기준으로 자동 객체 등록 예외 클래스 지정
dispatcher-servlet.xml
Session
Controller 단에서 처리하는 방식
- HttpSession을 활용
- HttpServletRequest를 활용
- @SessionAttributes("세션key")
@modelAttribute("세션key")