Java后端實現頁面跳轉


Java后端實現頁面跳轉

頁面跳轉分類有兩種:重定向和轉發,即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");

二:轉發forward

 request.getRequestDispatcher("/student_list.jsp").forward(request, response);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM