I am new to servlets, Help me understand Filter concept in real time?
Asked
Active
Viewed 501 times
-5
-
servlets is quite ancient. if you start learning, learn new material. there is a big difference between "real life" and "real time", btw – Stultuske Dec 19 '17 at 09:49
-
a filter is called *before* the client request reaches your Servlet. It acutally *filters* the request and redirects them if necessary. For example you could use a filter to check whether the client is logged in or not. The filter would then send the client to the servlet it requested when it is logged in or the filter could redirect the client to the login page (just an example) - sorry, I forgot to mention the filters that handle the request *after* the servlet was executed. But you get the idea? – GameDroids Dec 19 '17 at 09:50
-
1@Stultuske the Servlet API is still the base (for better or worse) for many frameworks and it's not a bad idea to understand how it works. It's only recently that Spring for example introduced [Webflux](https://docs.spring.io/spring-framework/docs/5.0.0.BUILD-SNAPSHOT/spring-framework-reference/html/web-reactive.html) which is not dependent on the Servlet API. – Kayaman Dec 19 '17 at 09:50
1 Answers
2
Filters help you to intercept the incoming request and response. Request filters can: perform security checks, reformat request headers or bodies, audit or log requests,
Response filters can: compress the response stream, append or alter the response stream, create a different response altogether.

riteshmaurya
- 166
- 1
- 11