springmvc学习笔记(24)——重定向和转发

重定向
重定向也是web开发中常用的,在springmvc中,重定向相当的简单

    @RequestMapping("/index")
    public String index(){
        return "redirect:hello";
    }

轻轻松松,转发给hello.jsp

转发
同样的,转发网页也是一样的方法   

 @RequestMapping("/index")
    public String index(){
        return "forward:hello";
    }

response.sendRedirect(absolutePath + "/a/forbidden");

 重定向和转发都是以HttpRequest为基础的。他们寻找的是controller中的路径。

例如上面的/a/forbidden

是:

猜你喜欢

转载自blog.csdn.net/qq_36826506/article/details/85010700