beginnerFoundations: What Is Security, and Why Should You Care?
What is a Servlet Filter, and how is it different from a Servlet?
A Servlet handles a request and generates a response (the end of the pipeline — e.g., DispatcherServlet). A Filter intercepts requests/responses before and after they reach a servlet, and multiple filters can be chained. Filters are reusable, composable, cross-cutting units (logging, compression, security) that don't need to know about each other or about the servlet.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response