关于在SPRING中的页面跳转和重定向(Forward&Redirect)
2008-03-12 15:01
651 查看
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.
通过在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中的页面跳转和重定向(Forward&Redirect)
- 关于在SPRING中的页面跳转和重定向(Forward&Redirect)
- 关于在SPRING中的页面跳转和重定向(Forward&Redirect)
- 跳转(Forward)和页面重定向(Redirect)的区别
- 跳转(Forward)和页面重定向(Redirect)的区别
- java web工程中关于redirect重定向和forward页面转发的区别
- spring mvc redirect 重定向 跳转并传递参数 && mvc:view-controller直接转发页面
- 关于页面跳转(转发重定向)和作用域的知识总结
- 项目访问是直接页面 <jsp:forward page="i/1/1"/>跳转前加操作逻辑
- spring jquery Mobile 页面跳转后浏览器url未改变&&javaScript代码刷新后才能执行的问题解决
- Spring Security4.1.3实现拦截登录后向登录页面跳转方式(redirect或forward)返回被拦截界面
- 关于Servlet里用sendRedirect 或 forward 来跳转到其它页面
- 【学习摘记】马士兵Servlet&JSP_课时24_forward_sendredirect——原页面跳转 vs 新页面跳转
- forward转发&redirect重定向
- springMVC3学习(九)--redirect和forward跳转
- 转贴:关于内部重定向(forward)和外部重定向(redirect)
- 关于dwz框架中回调函数是进行页面跳转(callbackType=forward)时偶尔会出现页面输入框无法编辑的情况
- 重定向redirect与跳转forward区别
- Spring Security4.1.3实现拦截登录后向登录页面跳转方式(redirect或forward)返回被拦截界面
- springMVC3学习(九)--redirect和forward跳转