Class AbstractController

All Implemented Interfaces:
ApplicationContextAware, Controller
Direct Known Subclasses:
BaseCommandController, ParameterizableViewController

public abstract class AbstractController
extends WebContentGenerator
implements Controller

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

Exposes the following bean properties:

Rod Johnson

Fields inherited from class
Constructor Summary
          Create a new Controller supporting GET and POST methods.
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.
protected abstract  ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Template method.
 void setCacheSeconds(int seconds)
          If 0 disable caching, default is no caching header generation.
 void setRequireSession(boolean requireSession)
          Is a session required to handle requests?
 void setSupportedMethods(java.lang.String[] supportedMethodsArray)
          Set supported methods as CSV.
Methods inherited from class com.interface21.web.servlet.mvc.WebContentGenerator
cacheForSeconds, preventCaching, setUseExpiresHeader
Methods inherited from class
getApplicationContext, initApplicationContext, setApplicationContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public AbstractController()
Create a new Controller supporting GET and POST methods.
Method Detail


public final void setSupportedMethods(java.lang.String[] supportedMethodsArray)
                               throws ApplicationContextException
Set supported methods as CSV. The String[] property editor will get the type right.


public final void setRequireSession(boolean requireSession)
Is a session required to handle requests?


public final void setCacheSeconds(int seconds)
If 0 disable caching, default is no caching header generation. Only if this is set to 0 (no cache) or a positive value (cache for this many seconds) will this class generate cache headers. They can be overwritten by subclasses anyway, before content is generated.


public final ModelAndView handleRequest(javax.servlet.http.HttpServletRequest request,
                                        javax.servlet.http.HttpServletResponse response)
                                 throws javax.servlet.ServletException,
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
Following copied from interface: com.interface21.web.servlet.mvc.Controller
request - current HTTP request
response - current HTTP response
a ModelAndView to render, or null if handled directly


protected abstract ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request,
                                                      javax.servlet.http.HttpServletResponse response)
                                               throws javax.servlet.ServletException,
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)

Rod Johnson and Spring contributors 2001-2003.