Taking a request from a browser window and processing it by using multiple servlets as a chain is called Servlet Chaining. In servlet chaining, communication occurs between servlet chains and servlet programs to process the request given by a client.
This is a process to make available the user's request to multiple servlets. A user provides request to the first servlet present in the chain. The first servlet uses the form fields present in the request. It can transfer the request to another servlet with the execution control. The second servlet can use the request, as it is available to it. This process can be repeated for any number of servlets. The last servlet present in the chain provides response to the user. All servlets present before the last servlet remain invisible to the user.
A question may come to your mind, as to why one would want to use a servlet chain when one could instead write a script that edits the files in place, especially when there is an additional amount of overhead for each servlet involved in handling a request? The answer is that servlet chains have a threefold advantage:
• They can be easily undone.
• They handle dynamically created content, so you can trust that your restrictions are maintained, your special tags are replaced, and your dynamically converted PostScript images are properly displayed, even in the output of a servlet (or a CGI script).
• They handle the content of the future, so you do not have to run your script every time new content is added.
• All servlet programs that participate in the servlet chaining will use some request and response objects because they process the same request that is given by the client.
• To perform servlet chaining we need RequestDispatcher object. RequestDispatcher object means it is the object of a container supplied Java class implementing javax. servlet.RequestDispatcher interface.