通过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";
}
}