The request dispatcher serves as an interface utilized to effectively redirect requests to various resources within the application itself. These resources may include Java Server Pages (JSP), images, HTML files, or other servlets. Moreover, it facilitates the integration of responses from one servlet into another, guaranteeing that the client receives output from both servlets. Additionally, it allows for the seamless forwarding of client requests to the next servlet in the specified sequence.
There are two methods defined in a Requestdispatcher interface:
void include(): It includes the content of the resource before sending the response.
void forward(): the method forwards the request from one servlet to another resource like the JSP, image, etc on the server.