java后端怎样完成页面跳转【JAVA教程】,java,后端,实现,页面跳转
页面跳转分类有两种:重定向和转发,即redirect
和forward
。
一:重定向redirect
第一种体式格局:controller中返回值为String
相干免费进修视频分享:java在线进修
public String login(HttpServletRequest req, HttpServletResponse resp) return "redirect:http://localhost:8080/index";
第二种体式格局:controller中返回值为void
public void login(HttpServletRequest req, HttpServletResponse resp) resp.sendRedirect("http://localhost:8080/index");
第三种体式格局:controller中返回值为ModelAndView
return new ModelAndView("redirect:/toList");
二:转发forward
比方:
request.getRequestDispatcher("/student_list.jsp").forward(request, response);
相干文章教程引荐:java入门教程
以上就是java后端怎样完成页面跳转的细致内容,更多请关注ki4网别的相干文章!