Java Reference
In-Depth Information
6. If one or more interceptors have been configured, the preHandle method is
invoked on each one of them to preprocess a request.
7. The doDispatch method gets an instance of a page controller by invoking the
getHandler method on HandlerExecutionChain .
8. Just like handler mappings, there can be multiple handler adapters registered with
the Spring MVC framework. The getHandlerAdapter() method of the front con-
troller servlet looks up the list of handler adapters to find the one most suitable for
executing the selected page controller.
9. Once the handler adapter is found, the request processing is delegated to its
handle() method.
10. The handle() method is responsible for invoking the correct page controller meth-
ods and converting the returned value into a type that the Spring MVC framework
understands.
11. Finally, any postprocessing task is carried out with the help of the interceptors.
Using Action Handlers
As shown earlier, HandlerMapping along with HandlerAdapter forms the backbone of the
robust and highly flexible Spring action management component. They bring the flexibil-
ity of program to interface (P2I), thus allowing different concrete implementations. Both
the handler mapping and the handler adapter provide extension points into the Spring
MVC framework. Let's say you need to map a page controller based on a value set in a
cookie. You can achieve this with a custom handler mapping implementation. Assume
that this page controller was developed as part of some homegrown web framework. You
can create a handler mapping implementation to invoke appropriate methods on this
controller and consume the returned results. Using the customized version is as simple
as implementing the interfaces or any of the abstract classes and then configuring it with
the Spring container. However, this is not required in most cases. This is because Spring
provides several concrete implementations that are sufficient in most cases. I have been
explaining a lot of theoretical stuff so far, so I will now show how to put the implementa-
tion classes into action.
BeanNameUrlHandlerMapping
This handler mapping is used to map the request URL directly to the bean object or
a page controller registered in the Spring IOC container. In other words, the URL is
 
Search WWH ::




Custom Search