本文共 1168 字,大约阅读时间需要 3 分钟。
@RequestMapping("/tiaozhuan") public void test(HttpServletRequest req, HttpServletResponse resp) throws Exception { resp.getWriter().println("这是跳转的新页面"); ->输出流 //resp.sendRedirect("index.jsp");或者.html ->重定向 //req.getRequestDispatcher("index.jsp").forward(req,resp); ->转发 }
@RequestMapping("/tiaozhuan") public String test(){ return "index.jsp"; //转发 return "forward:index.jsp"; //转发 return "redirect:index.jsp"; //重定向 }
@RequestMapping("/tiaozhuan") public String hello1(){ return "index"; //转发 return "forward:index"; //转发 return "redirect:index"; //重定向 也可以跳转到controller }
@RequestMapping("/tiaozhuan")public ModelAndView test(HttpServletRequest req,HttpServletResponse resp) throws Exception { ModelAndView mv = new ModelAndView(); //域中添加数据 mv.addObject("msg","跳转成功"); //视图名称跳转 mv.setViewName("index"); return mv;
转载地址:http://vxoyk.baihongyu.com/