RequestDispatcher
Forward
1. If the Forward URL contains parameters with the same name as the existing parameters in the request object, the getParameter method returns the parameters in the Forward URL.
2. Before Forward, the container should read the parameters in POST Form Data.
3. If the Forward URL contains the jsessionid parameter, the container treats it as a part of the URL without the SessionId.
4. Before the forward method is called, the container clears the output cache. If the data has been sent to the browser, IllegalStateException is thrown.
5. Before the forward method is returned, the container should send all the data to the browser and close the output stream. This means that after the forward method is called, all the data output using the output stream will be ignored.
6. Before forward, the container should reset the following attributes of the request according to the Forward URL: ServletPath, RequestURI, QueryString, PathInfo. RequestURL unchanged. If getNameDispatcher is used, you do not need to reset it.
7. When Forward requests, welcome files should be processed
8. Do not perform Filting during Forward.
9. The request and response parameters can be container implementation classes, ServletRequestWrapper, ServletResponseWrapper, or its subclass.
Include
1. If the Include URL contains parameters with the same name as the existing parameters in the request object, the getParameter method returns the parameters in the Include URL.
2. Before Include, the container should read the parameters in POST Form Data.
3. If the Include URL contains the jsessionid parameter, the container treats it as a part of the URL without the SessionId.
4. In the included Servlet, only the output content of the output stream is used. The response header cannot be set. All the settings are ignored, but no exception is thrown.
5. Before the include operation, the container does not reset the request attributes, but puts ContextPath, ServletPath, PathInfo, QueryString, and RequestURI In the attribute of the request (if getNameDispather is used)
Javax. servlet. include. context_path = ContextPath
Javax. servlet. include. servlet_path = ServletPath
Javax. servlet. include. path_info = PathInfo
Javax. servlet. include. query_string = QueryString
Javax. servlet. include. request_uri = RequestURI
6. do not perform Filting during the Include operation.
7. When the Include request is made, welcome files should not be processed.
8. The request and response parameters can be container implementation classes, ServletRequestWrapper, ServletResponseWrapper, or its subclass.
The URL of RequestDispatcher obtained through ServletContext is relative to that of ContextPath
The RequestDispatcher obtained through ServletRequest. Its URL is relative to the ServletPath of the initial request (if it is a string of forward, it is best to process the requested Servlet Path)
Call getNameDispatcher. If the Servlet does not exist, null is returned.