org.springframework.web.servlet.mvc
Interface Controller

All Known Implementing Classes:
BurlapServiceExporter, HessianServiceExporter, AbstractController, UrlFilenameViewController

public interface Controller

Base Controller interface, representing a component that receives HttpServletRequest and HttpServletResponse like a HttpServlet but is able to participate in an MVC workflow. Comparable to the notion of a Struts Action

Any implementation of the Controller interface should be a reusable, threadsafe class, capable of handling multiple HTTP requests throughout the lifecycle of an application. To be able to configure Controller in an easy, Controllers are usually JavaBeans.

Workflow:
After the DispatcherServlet has received a request and has done its work to resolve locales, themes and things a like, it tries to resolve a Controller, using a org.springframework.web.servlet.HandlerMapping HandlerMapping. When a Controller has been found, the \ handleRequest() method will be invoked, which is responsible for handling the actual request and - if applicable - returning an appropriate ModelAndView. So actually, this method is the main entrypoint for the DispatcherServlet which delegates requests to controllers. This method - and also this interface - should preferrably not be implemented by custom controllers directly, since abstract controller also provided by this package already provide a lot of functionality common for virtually all webapplications. A few examples of those abstract controllers: AbstractController, AbstractCommandController and AbstractFormController.

So basically any direct implementation of the Controller interface just handles HttpServletRequests and should return a ModelAndView, to be further used by the DispatcherServlet. Any additional functionality such as optional validation, formhandling, etcetera should be obtained by extended one of the abstract controller mentioned above.

Author:
Rod Johnson
Version: $Id: Controller.java,v 1.4 2003/12/09 08:48:40 jhoeller Exp $
See Also: SimpleControllerHandlerAdapter

Method Summary
 ModelAndViewhandleRequest(HttpServletRequest request, HttpServletResponse response)
          Process the request and return a ModelAndView object which the DispatcherServlet will render.

Method Detail

handleRequest

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws java.lang.Exception
Process the request and return a ModelAndView object which the DispatcherServlet will render. A null return is not an error: It indicates that this object completed request processing itself, thus there is no ModelAndView to render.
Parameters:
request - current HTTP request
response - current HTTP response
Returns: a ModelAndView to render, or null if handled directly
Throws:
Exception - in case of errors