@RequestMapping("/redirect")
public String redirect(HttpServletRequest request){
System.out.println("重定向");
String contextPath = request.getContextPath();
System.out.println(contextPath);
return "redirect:/pages/success.jsp";
}
//使用字符串重定向是经过mvc的不需要添加request.getContextPath()项目路径,第一个/已经代表了项目的虚拟路径
//无论该虚拟路径叫什么名字
@RequestMapping("/redi")
public void redi(HttpServletRequest request, HttpServletResponse response) throws IOException {
String contextPath = request.getContextPath();
System.out.println(contextPath);
response.sendRedirect(contextPath+"/pages/success.jsp");
}
//使用response对象的重定向是采用原生servlet实现的 必须加上request.getContextPath()项目虚拟路径
SpringMVC返回字符串请求转发和response请求转发的区别
最新推荐文章于 2023-05-05 16:21:23 发布