Interceptor
Introduction
Can perform logic and stop before sending the request to the controller ot before sending the response to the client
There are 3 methods:
preHandle() method − This is used to perform operations before sending the request to the controller. This method should return true to return the response to the client.
postHandle() method − This is used to perform operations before sending the response to the client.
afterCompletion() method − This is used to perform operations after completing the request and response.
Implementation
Difference between Filter
Filters intercept requests before they reach the DispatcherServlet
HandlerIntercepors, on the other hand, intercepts requests between the DispatcherServlet and our Controllers. This is done within the Spring MVC framework, providing access to the Handler and ModelAndView objects. This reduces duplication and allows for more fine-grained functionality
Last updated
Was this helpful?