Class AbstractController

              extended byorg.springframework.web.servlet.mvc.AbstractController
All Implemented Interfaces:
ApplicationContextAware, Controller
Direct Known Subclasses:
BaseCommandController, MultiActionController, ParameterizableViewController, ServletForwardingController, ServletWrappingController

public abstract class AbstractController
extends WebContentGenerator
implements Controller

Convenient superclass for controller implementations, using the Template Method design pattern.

As stated in the Controller interface, a lot of functionality is already provided by certain abstract base controllers. The AbstractController is one of the most important abstract base controller providing basic features such as the generation of caching headers and the enabling or disabling of supported methods (GET/POST).

Workflow (and that defined by interface):

  1. handleRequest() will be called by the DispatcherServlet
  2. Inspection of supported methods (ServletException if request method is not support)
  3. If session is required, try to get it (ServletException if not found)
  4. Set caching headers if needed according to cacheSeconds propery
  5. Call abstract method handleRequestInternal(), which should be implemented by extending classes to provide actual functionality to return ModelAndView objects.

Exposed configuration properties (and those defined by interface):

name default description
supportedMethods GET,POST comma-separated (CSV) list of methods supported by this controller, such as GET, POST and PUT
requireSession false whether a session should be required for requests to be able to be handled by this controller. This ensures, derived controller can - without fear of Nullpointers - call request.getSession() to retrieve a session. If no session can be found while processing the request, a ServletException will be thrown
cacheSeconds -1 indicates the amount of seconds to include in the cache header for the response following on this request. 0 (zero) will include headers for no caching at all, -1 (the default) will not generate any headers and any positive number will generate headers that state the amount indicated as seconds to cache the content

Rod Johnson, Juergen Hoeller
See Also:

Field Summary
Fields inherited from class
Fields inherited from class
Constructor Summary
Method Summary
 ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
          Process the request and return a ModelAndView object which the DispatcherServlet will render.
protected abstract  ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
          Template method.
 boolean isSynchronizeOnSession()
          Return whether controller execution should be synchronized on the session.
 void setSynchronizeOnSession(boolean synchronizeOnSession)
          Set if controller execution should be synchronized on the session, to serialize parallel invocations from the same client.
Methods inherited from class
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isRequireSession, isUseCacheControlHeader, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseExpiresHeader
Methods inherited from class
getServletContext, getTempDir, getWebApplicationContext, isContextRequired
Methods inherited from class
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public AbstractController()
Method Detail


public final void setSynchronizeOnSession(boolean synchronizeOnSession)
Set if controller execution should be synchronized on the session, to serialize parallel invocations from the same client.

More specifically, the execution of the handleRequestInternal method will get synchronized if this flag is true.

See Also:
handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)


public final boolean isSynchronizeOnSession()
Return whether controller execution should be synchronized on the session.


public final ModelAndView handleRequest(HttpServletRequest request,
                                        HttpServletResponse response)
                                 throws Exception
Description copied from interface: Controller
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.

Specified by:
handleRequest in interface Controller
request - current HTTP request
response - current HTTP response
a ModelAndView to render, or null if handled directly
Exception - in case of errors


protected abstract ModelAndView handleRequestInternal(HttpServletRequest request,
                                                      HttpServletResponse response)
                                               throws Exception
Template method. Subclasses must implement this. The contract is the same as for handleRequest.

See Also:
handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

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