The Spring HandlerInterceptor interface
Spring's request handling mapping mechanism includes the ability to intercept requests by using handler interceptors. These interceptors are used to apply some type of functionality to the requests as in our example of checking whether a user is in session. The interceptors must implement the HandlerInterceptor
interface from the org.springframework.web.servlet
package where it is possible to apply the functionality in the following three ways:
Before the handler method is executed by implementing the
preHandle
methodAfter the handler method is executed by implementing the
postHandle
methodAfter the complete request has finished execution by implementing the
afterCompletion
method
The HandlerInterceptorAdapter
abstract class, along with the predefined empty implementations for each method, is normally used to implement custom handlers. Our UserInSessionInterceptor
class is defined as follows:
package com.gieman.tttracker.web; import com.gieman.tttracker...