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:
javax.servlet.include.request_uri
javax.servlet.include.context_path
javax.servlet.include.servlet_path
javax.servlet.include.path_info
javax.servlet.include.query_string
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.
For forward () :
javax.servlet.forward.request_uri
javax.servlet.forward.context_path
javax.servlet.forward.servlet_path
javax.servlet.forward.path_info
javax.servlet.forward.query_string
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.