org.springframework.web.servlet
Interface HandlerMapping

All Known Implementing Classes:
AbstractHandlerMapping

public interface HandlerMapping

Interface to be implemented by objects that define a mapping between requests and handler objects.

This class can be implemented by application developers, although this is not necessary, as BeanNameUrlHandlerMapping and SimpleUrlHandlerMapping are included in the framework. The former is the default if no HandlerMapping bean is registered in the application context.

HandlerMapping implementations can support mapped interceptors but do not have to. A handler will always be wrapped in a HandlerExecutionChain instance, optionally accompanied by some HandlerInterceptor instances. The DispatcherServlet will first call each HandlerInterceptor's preHandle method in the given order, finally invoking the handler itself if all preHandle methods have returned "true".

The ability to parameterize this mapping is a powerful and unusual capability of this MVC framework. For example, it is possible to write a custom mapping based on session state, cookie state or many other variables. No other MVC framework seems to be equally flexible.

Note: Implementations can implement the Ordered interface to be able to specify a sorting order and thus a priority for getting applied by DispatcherServlet. Non-Ordered instances get treated as lowest priority.

Author:
Rod Johnson, Juergen Hoeller
See Also:
Ordered, AbstractHandlerMapping, BeanNameUrlHandlerMapping, SimpleUrlHandlerMapping

Method Summary
 HandlerExecutionChain getHandler(javax.servlet.http.HttpServletRequest request)
          Return a handler and any interceptors for this request.
 

Method Detail

getHandler

public HandlerExecutionChain getHandler(javax.servlet.http.HttpServletRequest request)
                                 throws java.lang.Exception
Return a handler and any interceptors for this request. The choice may be made on request URL, session state, or any factor the implementing class chooses.

The returned HandlerExecutionChain contains a handler Object, rather than even a tag interface, so that handlers are not constrained in any way. For example, a HandlerAdapter could be written to allow another framework's handler objects to be used.

Returns null if no match was found. This is not an error. The DispatcherServlet will query all registered HandlerMapping beans to find a match, and only decide there is an error if none can find a handler.

Parameters:
request - current HTTP request
Returns:
a HandlerExecutionChain instance containing handler object and any interceptors, or null if no mapping found
Throws:
java.lang.Exception - if there is an internal error


Copyright (C) 2003-2004 The Spring Framework Project.