Hi all,
I am having some understanding problem.
The following is from SRV.8.1
To allow RequestDispatcher objects to be obtained using relative paths that
are relative to the path of the current request (not relative to the root of the
ServletContext), the getRequestDispatcher method is provided in the
ServletRequest interface.
The behavior of this method is similar to the method of the same name in the
ServletContext. The servlet container uses information in the request object to
transform the given relative path against the current servlet to a complete path. For
example, in a context rooted at ’/’ and a request to /garden/tools.html, a request
dispatcher obtained via ServletRequest.getRequestDispatcher("header.html")
will behave exactly like a call to
ServletContext.getRequestDispatcher("/garden/header.html").
I could not understand the (underlined)example of relative path given. The request dispatcher is called from a
servlet then how can the request be /garden/tools.html. Should it not be like /garden/tools.do where tools.do is the servlet mapping to the servlet having requestDispatcher.
Also i could not understand another thing. In specification it is written:
The getRequestDispatcher method takes a String argument describing a
path within the scope of the ServletContext. This path must be relative to the root
of the ServletContext and begin with a ‘/’. The method uses the path to look up
a servlet, using the servlet path matching rules in Chapter SRV.11, “Mapping
Requests to Servlets”, wraps it with a RequestDispatcher object, and returns the
resulting object. If no servlet can be resolved based on the given path, a
RequestDispatcher is provided that returns the content for that path.
What is meaning of underlined text.
But the API says that getRequestDispatcher() method returns null if the servlet container cannot return a RequestDispatcher.
---Thanks and Regards.