zoukankan      html  css  js  c++  java
  • SpringMVC

    SpringMVC的跳转方式

    ModelAndView

    @RequestMapping("test3")
    public ModelAndView test3(ModelAndView modelAndView) {
        //指定要跳转的页面
        modelAndView.setViewName("a");
        return modelAndView;
    }
    

    ServletAPI

    //写数据
    @RequestMapping("t1")
    public void test1(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
        rsp.getWriter().println("Hello,Spring BY servlet API");
    }
    //重定向
    @RequestMapping("/result/t2")
    public void test2(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
        rsp.sendRedirect("/index.jsp");
    }
    //请求转发
    @RequestMapping("/result/t3")
    public void test3(HttpServletRequest req, HttpServletResponse rsp) throws Exception {
        req.setAttribute("msg","t3");
        req.getRequestDispatcher("a.jsp").forward(req,rsp);
    }
    

    SpringMVC

    • 下面的三个方式,不能有视图解析器
    //请求转达
    @RequestMapping("test5")
    public String test5() {
        return "/a.jsp";
    }
    //请求转达
    @RequestMapping("test6")
    public String test6() {
        return "forward:/a.jsp";
    }
    //重定向
    @RequestMapping("test7")
    public String test7() {
        return "redirect:/a.jsp";
    }
    
    • 这种的需要视图解析器
    @RequestMapping("test1")
    public String test1(){
        //转发
        return "test";
    }
    
    不经风雨,怎见彩虹?
  • 相关阅读:
    转载-如何高效的学习技术
    Lc176-第二高的薪水
    Lc4-寻找两个有序数组的中位数
    Lc175-组合两个表
    Lc3-无重复字符的最长子串
    Lc2-俩数相加
    Lc1- 两数之和
    jpa-子查詢
    20191225页面样式
    leetcode二刷结束
  • 原文地址:https://www.cnblogs.com/MLYR/p/14486373.html
Copyright © 2011-2022 走看看