SpringMVC的重定向和请求转发

一般的请求默认是转发

我们测试SpringMVC的转发和重定向的时候,先把视图解析器配置注释掉

请求:

forward

转发:

redirect
@Controller
public class ResultSpringMVC {


   @RequestMapping("/rsm/t2")
   public String test2(){
       //转发二
       return "forward:WEB-INF/jsp/index.jsp";
  }

   @RequestMapping("/rsm/t3")
   public String test3(){
       //重定向
       return "redirect:/index.jsp";   //重定向到首页
  }
}

 

posted @ 2021-12-05 17:18  qwedfrgh  阅读(37)  评论(0)    收藏  举报