Interface Controller

All Known Implementing Classes:
AbstractController, BurlapServiceExporter, HessianServiceExporter, 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.

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 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.

$Id:,v 1.5 2004/03/18 02:46:08 trisberg Exp $
Rod Johnson
See Also:

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

Method Detail


public ModelAndView handleRequest(javax.servlet.http.HttpServletRequest request,
                                  javax.servlet.http.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.

request - current HTTP request
response - current HTTP response
a ModelAndView to render, or null if handled directly
java.lang.Exception - in case of errors

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