특정 컨트롤러의 로직을 처리할 때, 다른 경로를 호출하는 경우가 있다. 이때 redirect: 를 사용한다.
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 32 33 34 35 36 37 38 39 40 41 42 43 | /* * SampleContoller4 * Use RedirectAttribute for calling another path * Use 'redirect:' */ package org.zerock.web; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.zerock.domain.ProductVO; @Controller public class SampleController4 { private static final Logger logger = // check the log LoggerFactory.getLogger(SampleController4.class); @RequestMapping("/doE") public String doE(RedirectAttributes rttr){ logger.info("################## doE ##################"); logger.info("redirect to doF"); // when we send temporary data, use 'addFlashAttribute' rttr.addFlashAttribute("msg", "redirected message!!!"); // use 'redirect:' return "redirect:/doF"; } @RequestMapping("/doF") public void doF(String msg) { logger.info("################## doF ##################"); logger.info("doF : " + msg); } } | cs |
결과 : http://localhost:8080/doE 라고 입력을 하면..http://localhost:8080/doF 경로로 redirect 된 결과가 호출 된다.
'문돌이의 IT > Spring' 카테고리의 다른 글
Uncaught ReferenceError: jQuery is not defined (0) | 2017.07.16 |
---|---|
how to create JSON data in Spring (0) | 2017.02.05 |
[Spring] how to use ModelAttribute (0) | 2017.02.03 |
[Spring]Controller, annotation 기능 확인 (0) | 2016.12.21 |
[Spring]servlet-context.xml (0) | 2016.12.20 |