SpringMVC- Path Forwarding and Redirection

1. forward prefix: forwarded to a page or action

  Not spell the string parser view our configuration, independent analytical, be sure to add "/", that is, without a relative path, easy to go wrong;

  "Forward to a jsp page:

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

  "Forward to action:

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

2. redirect prefix: redirect to a page or action

  "Redirect to jsp page:

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

  "Redirect to action:

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

 

Guess you like

Origin www.cnblogs.com/luliang888/p/11074889.html