SpringMVC-转发和重定向

通过SpringMVC实现转发和重定向
1.配置文件中没有视图解析器

@Controller
public class ResultSpringMVC {
    
    
   @RequestMapping("/rsm/t1")
   public String test1(){
    
    
       //转发
       return "/index.jsp";
  }

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

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

2.配置文件中配置了视图解析器

@Controller
public class ControllerTest2 {
    
    

    @RequestMapping("/test1")
    public String test1(){
    
    
        //转发
        return "test";
    }

    @RequestMapping("/test2")
    public String test2(){
    
    
        //重定向
        return "redirect:index.jsp";
    }
}

猜你喜欢

转载自blog.csdn.net/qq_42665745/article/details/112970843