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:
- It is based around a JavaBeans configuration mechanism.
- It can use any HandlerMapping implementation - whether standard, or provided
as part of an application - to control the routing of requests to handler objects.
Additional HandlerMapping objects can be added through defining beans in the
servlet's application context that implement the HandlerMapping interface in this
package. HandlerMappings can be given any bean name (they are tested by type).
- It can use any HandlerAdapter (additional HandlerAdapter objects can be added
through the application context).
- Its view resoltion strategy can be specified via a ViewResolver implementation.
Standard implementations support mapping URLs to bean names, and explicit mappings.
- Its locale resolution strategy is determined by a LocaleResolver implementation.
Standard implementations work via HTTP accept header, cookie, or session.
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
|
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 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 |
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
DispatcherServlet
public DispatcherServlet()
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.