Web components can invoke other Web resources in two ways: indirect and direct. A Web component indirectly invokes another Web resource when it embeds in content returned to a client a URL that points to another Web component. In the Duke's Bookstore application, most Web components contain embedded URLs that point to other Web components. For example,
ShowCartServletindirectly invokes the
CatalogServletthrough the embedded URL
A Web component can also directly invoke another resource while it is executing. There are two possibilities: it can include the content of another resource, or it can forward a request to another resource.
To invoke a resource available on the server that is running a Web component, you must first obtain a
RequestDispatcherobject using the
You can get a
RequestDispatcherobject from either a request or the Web context; however, the two methods have slightly different behavior. The method takes the path to the requested resource as an argument. A request can take a relative path (that is, one that does not begin with a
/), but the Web context requires an absolute path. If the resource is not available, or if the server has not implemented a
RequestDispatcherobject for that type of resource,
getRequestDispatcherwill return null. Your servlet should be prepared to deal with this condition.
Read more on Web Resource