Posts

Showing posts with the label Spring Interceptor

Using Spring Interceptor or Using Servlet Filter, how to get a Request URL template that has been hit?

Image
In this section, we will learn how to find a request URL template that has been hit using Servlet Filter or Using Spring Interceptor.  Before going to the example program just check the basis of the Servlet filter and Spring Interceptor. The Servlet Filter is used to intercept the client request and do some pre-processing before they reach the DispatcherServlet. It can also intercept the response and do post-processing before sending to the client in web application. On the other hand, The Spring Interceptor is only applied to requests that are sent to a Controller. Get request URL template using Spring Interceptor(Good approach) Demo Controller @ RequestMapping (path = "/user" ) @ RestController public class UserController { @ GetMapping (path = "/{id}" ) public ResponseEntity < Long > getAllVariables(@ PathVariable ( "id" ) Long id) { return new ResponseEntity < Long >(id, HttpStatus.OK); } } Custom I