页面跳转分类有两种:重定向和转发,即redirectforward

一:重定向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后端如何实现页面跳转的详细内容,更多请关注悠悠之家其它相关文章!

点赞(38)

评论列表共有 0 条评论

立即
投稿
返回
顶部