迪·杰西达邦·福尔迪:forward,include,redirect区别
来源:百度文库 编辑:九乡新闻网 时间:2024/05/03 01:02:21
forward,include,redirect是jsp中web页面(jsp或servelt)的三种不同的路由关系,三个貌似相同,其实还是有许多差别的,而了解这些细微的差别,在web开发中是很重要的。
说明:
一、forward、include由javax.servlet.RequestDispatcher来封装,由包容器container提供RequestDispatcher接口的实现,其中声明如下:
void forward(ServletRequest req,ServletResponse res)
void include(ServeltRequest req,ServletResponse res)
可以通过两种方式得到RequestDispatcher:
1、ServletContext.getRequestDispatcher(String path);
其中这里的path必须开始为 "/ ",即这里的path必须相对于context的root.
2、ServeltRequest.getRequestDispatcher(String path)
这里的path可以为相对路径,如果path开始为 "/ ",则也认为是从context的root开始的。
二、Redirect由HttpServletResponse.sendRedirect(String location)来支持
差别:
三个都可以对用户的request进行转发,但是还是有许多的不同,差别最主要集中在如下几个方面:
1、forward与include共亨Request范围内的对象,而redirect则不行,即:如果一个javabean被声明为request范围的话,则被forward到的资源也可以访问这个javabean,而redriect则不行。
2、forward与include基本上都是转发到context内部的资源,而redirect可以重定向到外部的资源,如: req.sendRedriect( "http://www.mocuai.com ");
说明:
一、forward、include由javax.servlet.RequestDispatcher来封装,由包容器container提供RequestDispatcher接口的实现,其中声明如下:
void forward(ServletRequest req,ServletResponse res)
void include(ServeltRequest req,ServletResponse res)
可以通过两种方式得到RequestDispatcher:
1、ServletContext.getRequestDispatcher(String path);
其中这里的path必须开始为 "/ ",即这里的path必须相对于context的root.
2、ServeltRequest.getRequestDispatcher(String path)
这里的path可以为相对路径,如果path开始为 "/ ",则也认为是从context的root开始的。
二、Redirect由HttpServletResponse.sendRedirect(String location)来支持
差别:
三个都可以对用户的request进行转发,但是还是有许多的不同,差别最主要集中在如下几个方面:
1、forward与include共亨Request范围内的对象,而redirect则不行,即:如果一个javabean被声明为request范围的话,则被forward到的资源也可以访问这个javabean,而redriect则不行。
2、forward与include基本上都是转发到context内部的资源,而redirect可以重定向到外部的资源,如: req.sendRedriect( "http://www.mocuai.com ");
forward,include,redirect区别
forward与include转发问题
forward与include转发问题 - yinyanshuan的日志 - 网易博客
#include 和 在FileView中添加工程文件的使用和区别(简化ClassView)
#include小结
会计专业英语[forward]_
Contain 与include 辨析
[Python]跳转(seeother)与重定向(redirect)
低调做人&高调做事(forward)
#include "stdafx.h" 作用2
PHP中include和require
Response.Redirect 打开新窗口的两种方法
Wind power forecasting: Looking forward, not ...
servlet: filter的FORWARD
China to push forward pragmatic cooperation w...
Proxy, Forward proxies, Open proxies, Reverse proxy
jsp:include flush标签的含义
中国佛学66句震撼世界的禅语(forward)
[Forward]静态时序分析(Static?Timing?Analysis)
考研英语词汇复习(9):expect、anticipate、look forward to
如何回答:would you mind doing sth, include "yes""no
Does the New Normal Include Private Unemployment Insurance?
Android布局整合include界面控件(重用布局)
China to push forward capital account convertibility over next 5 years