SpringMvc转发和重定向
SpringMVC
通过SpringMVC来实现转发和重定向 - 无需视图解析器;
测试前,不要配置springmvc的设图解析器
@Controller
public class ResultSpringMVC {
@RequestMapping("/a/t1")
public String test1(){
//转发
return "/index.jsp";
}
@RequestMapping("/a/t2")
public String test2(){
//转发二
return "forward:/index.jsp";
}
@RequestMapping("/a/t3")
public String test3(){
//重定向
return "redirect:/index.jsp";
}
}
通过SpringMVC来实现转发和重定向 - 有视图解析器;
重定向 , 不需要视图解析器 , 本质就是重新请求一个新地方嘛 , 所以注意路径问题.
可以重定向到另外一个请求实现 .
@Controller
public class ResultSpringMVC2 {
@RequestMapping("/b/t1")
public String test1(){
//转发
return "test";
}
@RequestMapping("/b/t2")
public String test2(){
//重定向
return "redirect:/index.jsp";
//return "redirect:hello.do"; //hello.do为另一个请求/
}
}
本文来自博客园,作者:Cn_FallTime,转载请注明原文链接:https://www.cnblogs.com/CnFallTime/p/16093846.html