Servlet/JSP Container development Note 5-RequestDispatcher

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.