1) Let's first understand how Request and Request Filter :
When, say, a client makes a request for a servlet, it passes through the container. The container decides which Request servlet should be redirected. This means that the container is fully controlled.
Container control simplifies the implementation of the query filter, since we can simply tell the container that Request must first go to filtering, and then to the servlet. Because the container is fully controlled. Therefore, implementing a query filter is easy.
2) Now let's understand how Response and Response Filter :
When a container calls Servlet service methods, it passes 2 methods to the methods, Request and Response .
It just means that Servlet has full control over sending a response to the client. How?
Because the Response object has a pointer to the Output Stream Writer object. This means that after Servlet finishes processing the request, it will hide the Response record back to the client using a pointer to the Output Writer Stream object. Thus, the servlet will not wait for anyone (the average man, like a filter), and directly serves the client. By then it will be too late to intervene.
So what are the solutions?
Wrapper is our solution.
How does Wrapper work?
So, before the container passes the real Request and Response objects to the Servlet, we wrap our Response object and then send the Real Request and Wrapped Response objects to the Servlet service services.
So now the servlet has a pointer to our Wrapped Output Stream Writer object, not the Real Response Output Stream Writer object. So, when Servlet completes the request, it will write a response to our Wrapped Stream , and then our Wrapped Response Object will return to Real Response Writer Stream .
The moral of the story: Use Wrapper when working with Response . Request does not require a shell concept.