티스토리 뷰

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 된다.

'BackEnd > Spring' 카테고리의 다른 글

[Spring] 예외처리  (1) 2016.04.14
[Spring] Command 객체 값 검증, Error 메세지  (0) 2016.04.14
[Spring] Spring 기본 4 (MVC)  (0) 2016.04.12
[Spring] Spring 기본 3 (MVC)  (0) 2016.04.12
[Spring] Spring 기본 2 (Maven)  (0) 2016.04.12
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함