页面跳转分类有两种:重定向和转发,即redirect
和forward
。
一:重定向redirect
第一种方式:controller中返回值为String
相关免费学习视频分享:java在线学习
复制代码1
2
public String login(HttpServletRequest req, HttpServletResponse resp)
return "redirect:http://localhost:8080/index";
登录后复制
第二种方式:controller中返回值为void
复制代码1
2
public void login(HttpServletRequest req, HttpServletResponse resp)
resp.sendRedirect("http://localhost:8080/index");
登录后复制
第三种方式:controller中返回值为ModelAndView
复制代码1
return new ModelAndView("redirect:/toList");
登录后复制
二:转发forward
例如:
复制代码1
request.getRequestDispatcher("/student_list.jsp").forward(request, response);
登录后复制
相关文章教程推荐:java入门教程
以上就是java后端如何实现页面跳转的详细内容,更多请关注靠谱客其它相关文章!
最后
以上就是外向硬币最近收集整理的关于java后端如何实现页面跳转的全部内容,更多相关java后端如何实现页面跳转内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复