Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring interceptor vs servlet filter

What advantages does a Spring interceptor have over a servlet filter?

like image 616
z12345 Avatar asked Jan 20 '12 13:01

z12345


People also ask

What is the difference between Spring interceptor and filter?

Filter is related to the Servlet API and HandlerIntercepter is a Spring specific concept. Interceptors will only execute after Filters. Fine-grained pre-processing tasks are suitable for HandlerInterceptors (authorization checks, etc.)

What is interceptor and filter?

Interceptors share a common API for the server and the client side. Whereas filters are primarily intended to manipulate request and response parameters like HTTP headers, URIs and/or HTTP methods, interceptors are intended to manipulate entities, via manipulating entity input/output streams.

What is the difference between servlet and filter?

Filter provides functionality which can be “attached” to any web resource. Servlet used for performing action which needs for particular request as user login, get response based on user role, interacts with database for getting data, business logic execution, and more.

Which is called first filter or interceptor?

So the order goes from 1. Filter ➡️ 2. Interceptor ➡️ 3. Controller for a HTTP request.


1 Answers

  • You can inject other beans in the interceptor
  • You can use more advanced mapping patterns (ant-style)
  • You have the target handler object (controller) available, as well as the result ModelAndView
  • It is a bean, so you can use AOP with it (althoug that would be rare)
like image 125
Bozho Avatar answered Oct 07 '22 06:10

Bozho