org.springframework.web.servlet
Class DispatcherServlet

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended byorg.springframework.web.servlet.HttpServletBean
              extended byorg.springframework.web.servlet.FrameworkServlet
                  extended byorg.springframework.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 web MVC framework. Dispatches to registered handlers for processing a web request.

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 dispatcher servlets. Each servlet will operate in its own namespace. Only the root application context, and any config objects set for the application as a whole, will be shared.

Version:
$Id: DispatcherServlet.java,v 1.29 2004/03/18 02:46:07 trisberg Exp $
Author:
Rod Johnson, Juergen Hoeller
See Also:
HandlerMapping, HandlerAdapter, ViewResolver, MultipartResolver, LocaleResolver, ThemeResolver, WebApplicationContext, ContextLoaderListener, Serialized Form

Field Summary
static java.lang.String EXCEPTION_RESOLVER_BEAN_NAME
          Well-known name for the ExceptionResolver object in the bean factory for this namespace.
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 MULTIPART_RESOLVER_ATTRIBUTE
          Request attribute to hold current multipart resolver, retrievable by views/binders.
static java.lang.String MULTIPART_RESOLVER_BEAN_NAME
          Well-known name for the MultipartResolver object in the bean factory for this namespace.
protected  org.apache.commons.logging.Log pageNotFoundLogger
          Additional logger for use when no mapping handlers are found for a request.
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 org.springframework.web.servlet.FrameworkServlet
DEFAULT_CONTEXT_CLASS, DEFAULT_NAMESPACE_SUFFIX, SERVLET_CONTEXT_PREFIX
 
Fields inherited from class org.springframework.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  long getLastModified(javax.servlet.http.HttpServletRequest request)
          Override HttpServlet's getLastModified to evaluate the Last-Modified value of the mapped handler.
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 org.springframework.web.servlet.FrameworkServlet
createWebApplicationContext, destroy, doGet, doPost, getContextClass, getContextConfigLocation, getNamespace, getServletContextAttributeName, getWebApplicationContext, initServletBean, initWebApplicationContext, isPublishContext, setContextClass, setContextConfigLocation, setNamespace, setPublishContext
 
Methods inherited from class org.springframework.web.servlet.HttpServletBean
init, setRequiredProperty
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, service, service
 
Methods inherited from class javax.servlet.GenericServlet
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

MULTIPART_RESOLVER_BEAN_NAME

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

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

EXCEPTION_RESOLVER_BEAN_NAME

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

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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

MULTIPART_RESOLVER_ATTRIBUTE

public static final java.lang.String MULTIPART_RESOLVER_ATTRIBUTE
Request attribute to hold current multipart resolver, retrievable by views/binders.

See Also:
RequestContextUtils

THEME_RESOLVER_ATTRIBUTE

public static final java.lang.String THEME_RESOLVER_ATTRIBUTE
Request attribute to hold current theme, retrievable by views.

See Also:
RequestContext

pageNotFoundLogger

protected final org.apache.commons.logging.Log pageNotFoundLogger
Additional logger for use when no mapping handlers are found for a request.

Constructor Detail

DispatcherServlet

public DispatcherServlet()
Method Detail

initFrameworkServlet

protected void initFrameworkServlet()
                             throws javax.servlet.ServletException,
                                    BeansException
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
Throws:
javax.servlet.ServletException - in case of an initialization exception
BeansException - if thrown by ApplicationContext methods

doService

protected void doService(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response)
                  throws java.lang.Exception
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.

Specified by:
doService in class FrameworkServlet
Throws:
java.lang.Exception - in case of any kind of processing failure
See Also:
HttpServlet.doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse), HttpServlet.doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

getLastModified

protected long getLastModified(javax.servlet.http.HttpServletRequest request)
Override HttpServlet's getLastModified to evaluate the Last-Modified value of the mapped handler.



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