頁(yè)面跳轉(zhuǎn)分類有兩種:重定向和轉(zhuǎn)發(fā),即redirect
和forward
。
一:重定向redirect
第一種方式:controller中返回值為String
相關(guān)免費(fèi)學(xué)習(xí)視頻分享:java在線學(xué)習(xí)
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");
二:轉(zhuǎn)發(fā)forward
例如:
request.getRequestDispatcher("/student_list.jsp").forward(request, response);
相關(guān)文章教程推薦:java入門(mén)教程