BackEnd/Spring
[Spring] Redirect 처리
best
2016. 4. 14. 15:10
Redirect 처리
Controller에서 클라이언트의 요청을 처리한 후 다른 페이지로 Redirect 하고 싶을 경우
return "redirect:/home"; 과 같이 처리
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 |
@RequestMapping(value="/login", method=RequestMethod.GET)
public String login(HttpSession session) {
if( session.getAttribute("_MEMBER_") != null ){
//로그인을 했을 때의 처리
// return "redirect:http://www.daum.net"; 절대 URL ( 다른 도메인에서의 절대 URL )
// return "redirect:home"; 상대 URL
// http://localhost:8080/home
// Redirect는 response.sendRedirect와 같이 대량의 데이터를 보낼 수 없다.
return "redirect:/home"; //같은 도메인 내에서의 절대 URL
}
// WEB-INF/view/login/login.jsp
return "login/login";
} |
cs |
"/"로 시작하지 않으면 @RequestMapping 경로를 기준으로 Redirect 된다.
"redirect:" 뒤에 완전한 URL을 적는다면, 해당 URL로 Redirect 된다.