리다이렉트(redirect:) 키워드 - CASE 1 - 조건을 통한 리다이렉트, CASE 2 - 실제 경로로 리다이렉트, CASE 3 - 리다이렉트를 통한 리다이렉트

CODEDRAGON Development/Spring

반응형

 

리다이렉트(redirect:) 키워드

다른 페이지로 이동할 때 사용됩니다.

·         CASE 1 - 조건을 통한 리다이렉트

·         CASE 2 - 실제 경로로 리다이렉트

·         CASE 3 - 리다이렉트를 통한 리다이렉트

 

 

 

CASE 1 - 조건을 통한 리다이렉트

/ch07ex05/src/main/java/com/codelab/ch07ex05/RedirectController.java

@RequestMapping("/studentConfirm")

public String studentRedirect(HttpServletRequest httpServletRequest, Model model){

String id = httpServletRequest.getParameter("id");

if(id.equals("codedragon")) {

return "redirect:studentOk";

}

return "redirect:studentError";

}

@RequestMapping("/studentOk")

public String studentOk(Model model){

return "student/studentOk";

}

@RequestMapping("/studentError")

public String studentError(Model model){

return "student/studentError";

}

 

 

 

CASE 2 - 실제 경로로 리다이렉트

@RequestMapping("/studentURL1")

public String studentURL1(Model model) {

return "redirect:http://localhost:8080/ch07ex05/

studentURL1.jsp";

}

 

 

 

CASE 3 - 리다이렉트를 통한 리다이렉트

@RequestMapping("/studentURL2")

public String studentURL2(Model model) {

return "redirect:student/studentURL2";

}

@RequestMapping("/student/studentURL2")

public String studentURL22(Model model) {

return "redirect:http://localhost:8080/ch07ex05/

classroom/studentURL2.jsp";

}

 

 

반응형