com.interface21.web.servlet
Class DispatcherServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--com.interface21.web.servlet.HttpServletBean
                    |
                    +--com.interface21.web.servlet.FrameworkServlet
                          |
                          +--com.interface21.web.servlet.DispatcherServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class DispatcherServlet
extends FrameworkServlet

Concrete front controller for use within the Interface21 MVC framework.
This class and the MVC approach it delivers is discussed in Chapter 12 of Expert One-On-One J2EE Design and Development by Rod Johnson (Wrox, 2002).

This servlet is very flexible: It can be used with just about any workflow, with the installation of the appropriate adapter classes.

It offers the following functionality that distinguishes it from other MVC frameworks:

A web application can use any number of controller servlets. Each servlet will operate in its own namespace. Only the default name space, and any config objects set for the application as a whole, will be shared.

Version:
$Revision: 1.3 $
Author:
Rod Johnson, Juergen Hoeller
See Also:
HandlerMapping, HandlerAdapter, ViewResolver, LocaleResolver, WebApplicationContext, ContextLoaderListener, Serialized Form

Field Summary
static java.lang.String LOCALE_RESOLVER_ATTRIBUTE
          Request attribute to hold current locale, retrievable by views.
static java.lang.String LOCALE_RESOLVER_BEAN_NAME
          Well-known name for the LocaleResolver object in the bean factory for this namespace.
static java.lang.String THEME_RESOLVER_ATTRIBUTE
          Request attribute to hold current theme, retrievable by views.
static java.lang.String THEME_RESOLVER_BEAN_NAME
          Well-known name for the ThemeResolver object in the bean factory for this namespace.
static java.lang.String VIEW_RESOLVER_BEAN_NAME
          Well-known name for the ViewResolver object in the bean factory for this namespace.
static java.lang.String WEB_APPLICATION_CONTEXT_ATTRIBUTE
          Request attribute to hold current web application context.
 
Fields inherited from class com.interface21.web.servlet.FrameworkServlet
DEFAULT_NAMESPACE_SUFFIX, SERVLET_CONTEXT_PREFIX
 
Fields inherited from class com.interface21.web.servlet.HttpServletBean
logger
 
Constructor Summary
DispatcherServlet()
           
 
Method Summary
protected  void doService(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Obtain and use the handler for this method.
protected  void initFrameworkServlet()
          Overridden method, invoked after any bean properties have been set and the WebApplicationContext and BeanFactory for this namespace is available.
 
Methods inherited from class com.interface21.web.servlet.FrameworkServlet
doGet, doPost, getNamespace, getServletContextAttributeName, getWebApplicationContext, initServletBean, setContextClass, setNamespace, setPublishContext
 
Methods inherited from class com.interface21.web.servlet.HttpServletBean
addRequiredProperty, getIdentifier, init
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALE_RESOLVER_BEAN_NAME

public static final java.lang.String LOCALE_RESOLVER_BEAN_NAME
Well-known name for the LocaleResolver object in the bean factory for this namespace.

VIEW_RESOLVER_BEAN_NAME

public static final java.lang.String VIEW_RESOLVER_BEAN_NAME
Well-known name for the ViewResolver object in the bean factory for this namespace.

THEME_RESOLVER_BEAN_NAME

public static final java.lang.String THEME_RESOLVER_BEAN_NAME
Well-known name for the ThemeResolver object in the bean factory for this namespace.

WEB_APPLICATION_CONTEXT_ATTRIBUTE

public static final java.lang.String WEB_APPLICATION_CONTEXT_ATTRIBUTE
Request attribute to hold current web application context. Otherwise only the global web app context is obtainable by tags etc.

LOCALE_RESOLVER_ATTRIBUTE

public static final java.lang.String LOCALE_RESOLVER_ATTRIBUTE
Request attribute to hold current locale, retrievable by views.
See Also:
RequestContext

THEME_RESOLVER_ATTRIBUTE

public static final java.lang.String THEME_RESOLVER_ATTRIBUTE
Request attribute to hold current theme, retrievable by views.
See Also:
RequestContext
Constructor Detail

DispatcherServlet

public DispatcherServlet()
Method Detail

initFrameworkServlet

protected void initFrameworkServlet()
                             throws javax.servlet.ServletException
Overridden method, invoked after any bean properties have been set and the WebApplicationContext and BeanFactory for this namespace is available.

Loads HandlerMapping and HandlerAdapter objects, and configures a ViewResolver and a LocaleResolver.

Overrides:
initFrameworkServlet in class FrameworkServlet
Following copied from class: com.interface21.web.servlet.FrameworkServlet
Throws:
javax.servlet.ServletException - in case of an initialization exception

doService

protected void doService(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response)
                  throws javax.servlet.ServletException,
                         java.io.IOException
Obtain and use the handler for this method. The handler will be obtained by applying the servlet's HandlerMappings in order. The HandlerAdapter will be obtained by querying the servlet's installed HandlerAdapters to find the first that supports the handler class. Both doGet() and doPost() are handled by this method. It's up to HandlerAdapters to decide which methods are acceptable.
Overrides:
doService in class FrameworkServlet
Following copied from class: com.interface21.web.servlet.FrameworkServlet
See Also:
HttpServlet.doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)


Rod Johnson and Spring contributors 2001-2003.