1,Redirect的两种方式:
通过在controller的new ModelAndView:
return new ModelAndView(new RedirectView(this.getViewFilename()));
通过在controller中使用HttpServletResponse实例:
response.sendRedirect(this.getViewFilename());
return null;
注意:redirect是针对document root的
2,Forward:
通过在controller的HttpServletRequest实例:
request.getRequestDispatcher(this.getViewFilename()).forward(request, response);
注意:forward是针对context root的
ps:Comments:
1. The redirect URL will be shown in browser, while the forward URL won’t.
2. Redirect could go out of the current web context, while forward can’t.
3. Chain actions: Since the web layer is very small, normally there is no need to chain the controllers together because the only functionality is to send out the view. However, in some cases, when we want to avoid duplicated code, we want to chain certain controllers together. For example, certain global pulldown menu shown in every page, or certain breadcrumbs. Right now, this is not supported, and it’s hard to change the code to support this because of the restriction on errors.getModel() (see below). Another way to do this is through interceptors where we can just pass back the models, not the views.
4. In terms of workflow, we might need to chain actions, there is a wizard form controller.
5. include should work in the same way.
分享到:
相关推荐
spring mvc controller间跳转 重定向 传参
SPring注解及页面跳转实例
介绍一个基于Spring Boot 3.0、Spring Cloud 2022 & Alibaba的微服务RBAC权限管理系统。该系统可以实现微服务RBAC权限管理,通过RBAC权限管理机制对用户访问系统的权限进行限制,从而提高系统的安全性和可用性。同时...
基于 Spring Boot + MyBatis Plus + Vue & Element 实现的后台管理系统 + 微信小程序 基于 Spring Boot + MyBatis Plus + Vue & Element 实现的后台管理系统 + 微信小程序 基于 Spring Boot + MyBatis Plus + Vue ...
spring mvc重定向导致内存溢出解决方案
主要介绍了详解spring mvc 请求转发和重定向,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
深入理解Spring Cloud与微服务构建+Git&GitHub;+Spring Boot+Spring in action+SpringBoot实战
Spring基础教程 (PDF格式)&& Spring in action 学习Spring的好资料, 包括Spring in aciont 源码 帮助大家快速理解掌握Spring技术
弹簧重定向 在Spring中重定向的不同方法
23-Spring Cloud网关&负载均衡 Zuul&Ribbon1
一个基于Spring Boot 3、 Spring Cloud 2021 & Alibaba、 -dolphin
Spring Boot项目导出war包放到tomcat运行跳转到页面出现404报错
该压缩包实现了利用过滤器或者拦截器对登录信息进行验证跳转登陆页的功能,利用的是SpringBoot和thymeleaf,使用前请先看使用说明
基于IntelliJ IDEA,spring mvc,maven,tomcat,实现了web下,用三种方式来访问某个页面,以及页面之间的跳转
在java Web编程中间经常出现需要从一个页面跳转到另外一个页面,如何选择跳转方式一直是java Web编程...本文总结了JSP/Servlet、Struts2和Spring中的页面跳转方法,详细分析对比了请求转发和重定向、RequestDispatc...
主要介绍了SpringCloud URL重定向及转发代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Springboot+MyBatis+mysql+jsp页面跳转详细示例
一个简单的SpringBoot实例,通过控制器实现jsp页面的跳转。
主要介绍了Spring Security跳转页面失败问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
springboot整合mybatis 实现查询数据库,并且可以跳转页面,很简单,只需要几个配置就行。项目下载之后需要导入数据库文件,并且修改数据库的地址,就可以运行了。