dinsdag 3 juli 2007

Spring Interceptors

Interceptors are very useful to intercept changes in your web application. Think of switching language, changing user id, ... Before Spring you would probably implement this using a filter.

Spring has a default interceptor for the language called LocaleChangeInterceptor. Look at the source of this one to see what you can do with interceptors.

It implements the HandlerInterceptor interface with the following methods (read api for more info):

void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)

Callback after completion of request processing, that is, after rendering the view.

void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)

Intercept the execution of a handler.

boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)

Intercept the execution of a handler.

To ease implementing only those you really need to implement there is the HandlerInterceptorAdapter.

Another example of using interceptors is to detect caching rules according to annotations


work out an example

Geen opmerkingen:

Een reactie plaatsen