I'm reading servlet specification and got a doubt about the forward and request parameters. It is explained in page 65-66 of servlet specification. When ever we use include or forward of RequestDispatcher , it sets few attributes in the request.
For example inlcude () sets following is the list of attributes:
These attributes are accessible from the included servlet via the getAttribute method on the request object and their values must be equal to the request URI,context path, servlet path, path info, and query string of the included servlet,respectively. If the request is subsequently included, these attributes are replaced for that include.
The values of these attributes must be equal to the return values of the HttpServletRequest methods getRequestURI, getContextPath, getServletPath, getPathInfo, getQueryString respectively, invoked on the request object passed to the first servlet object in the call chain that received the request from the client.
This means that always attributes related to forward() method returns the original request values where as the attributes related to include returns the values based on the included file(servlet/JSP).
Why is this difference present? I didn't understand it . Please anyone explain me.
In the forword, you may want to track the request from where it is came from. The forward page forwaod the page to different resource and the contains are on included in the processing of original request.
In the same way , in the include you want to know where the request is actually processed. In this case the contents are included in the output of original resource.