In this tutorial you will learn how a web component call to another web resources.
There can another web resources be called by the web components in both direct and indirect way. A web resource that a web component has called is an indirect way of calling by including an URL, this URL indicates the another web component which content will be returned to a client. However a web component calls another web resources directly during its execution, it can be called by either embedding content or by forwarding a request to another resource.
To call a resource it should be available on server, so it is required to get first the RequestDispatcher object. You can get the object of RequestDispatcher by using the getRequestDispatcher("URL") method. This method will return null if either the requested resource is not available or for the requested resource RequestDispatcher object is not implemented by the server.
include(request, response) method of RequestDispatcher object embedded the content with response of another resource while it is returned by the web component. Using this method you can write to the response body but, can't be set headers or call any method.
Transferring a control to the another web component is sometimes required in the case of where you want to perform some preliminary processing of a request by one web component and the response generation is perform by the another component.
javax.servlet.forward.[request-uri|context-path|servlet-path|path-info|query-string] method of RequestDispatcher is used to transfer the control from one web component to another. The requested URL locates the page that is responsible for replying to the user.
getServletContext() method is used to find out the web context, context is an object that implements the ServletContext interface, where the web components are executed. Methods of web context allows to access the following :
getAttribute() method is used by the filter to find out the counter object's.
Liked it! Share this Tutorial