zoukankan      html  css  js  c++  java
  • controller请求转发,重定向

    了解

    转发(forward):浏览器地址不会改变,始终是同一个请求。
    重定向(sendRedirect): 浏览器地址会改变,是两个请求。

    转发forward

    有异常抛出就好了:
    跳首页:浏览器的url地址不变.可能会找不到静态文件:

      @GetMapping(value = "/index")
        @ApiOperation("首页")
        public void index(HttpServletRequest request, HttpServletResponse response)  throws Exception  {
       request.getRequestDispatcher("/index.html").forward(request, response);
       }
    

    重定向redirect

    controller中返回值为void

     @GetMapping(value = "/index")
        @ApiOperation("首页")
        public void index(HttpServletRequest request, HttpServletResponse response) throws IOException {
            response.sendRedirect("/index.html");
        }
    
     第三种方式:controller中返回值为ModelAndView
    

    return new ModelAndView(“redirect:/toList”);

    世界上所有的不公平都是由于当事人能力不足造成的.
  • 相关阅读:
    webpack 入门(1)入口(entry)出口(output
    npm 常用使用命令
    typora快捷键
    一些思考
    SED LEARN NOTE
    常用网站工具整理
    DFTC
    Notion使用技巧
    BASH LEARN NOTE
    STBC公式
  • 原文地址:https://www.cnblogs.com/javayida/p/13346794.html
Copyright © 2011-2022 走看看