SpringMVC-路径转发与重定向

1. forward前缀:转发到一个页面或一个action

  不会由我们配置的视图解析器拼串,独立解析,一定要加“/”,不加就是相对路径,容易出问题;

  》转发到jsp页面:

@RequestMapping("/handle")
public String handle() {
    return "forword:/index.jsp" ;
}

  》转发到action:

@RequestMapping("/handle1")
public String handle1() {
    return "forword:/msg" ;
}
@RequestMapping("/msg")
public String handle() {
    return "forword:/index.jsp" ;
}

2. redirect前缀:重定向到一个页面或一个action

  》重定向到jsp页面:

@RequestMapping("/handle")
public String handle() {
    return "redirect:/index.jsp" ;
}

  》重定向到action:

@RequestMapping("/handle1")
    public String handle1() {
        return "redirect:/msg" ;
    }
@RequestMapping("/msg")
public String msg() {
    return "redirect:/index.jsp" ;
}

猜你喜欢

转载自www.cnblogs.com/luliang888/p/11074889.html