這篇文章將為大家詳細(xì)講解有關(guān)java后端實現(xiàn)頁面跳轉(zhuǎn)的方法,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
頁面跳轉(zhuǎn)分類有兩種:重定向和轉(zhuǎn)發(fā),即redirect
和forward
。
一:重定向redirect
第一種方式:controller中返回值為String
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后端實現(xiàn)頁面跳轉(zhuǎn)的方法就分享到這里了,解決問題并不止文章中和大家分析的辦法,不過本文分析的方法準(zhǔn)確性是不容置疑的。如果想了解更多相關(guān)文章內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。