|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.servlet.GenericServlet javax.servlet.http.HttpServlet org.springframework.web.servlet.HttpServletBean org.springframework.web.servlet.FrameworkServlet org.springframework.web.servlet.DispatcherServlet
Central dispatcher for use within the web MVC framework, e.g. for web UI controllers or HTTP-based remote service exporters. Dispatches to registered handlers for processing a web request.
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 request-driven web MVC frameworks:
A web application can use any number of DispatcherServlets. Each servlet will operate in its own namespace. Only the root application context will be shared.
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). Note that it is called ControllerServlet there; it has been renamed since to emphasize its dispatching role and avoid confusion with Controller objects that the DispatcherServlet will dispatch to.
ContextLoaderListener
,
HandlerMapping
,
BeanNameUrlHandlerMapping
,
HandlerAdapter
,
SimpleControllerHandlerAdapter
,
Controller
,
HandlerExceptionResolver
,
SimpleMappingExceptionResolver
,
ViewResolver
,
InternalResourceViewResolver
,
MultipartResolver
,
CommonsMultipartResolver
,
LocaleResolver
,
AcceptHeaderLocaleResolver
,
ThemeResolver
,
FixedThemeResolver
,
Serialized FormField Summary | |
static String |
HANDLER_EXCEPTION_RESOLVER_BEAN_NAME
Well-known name for the HandlerExceptionResolver object in the bean factory for this namespace. |
static String |
HANDLER_EXECUTION_CHAIN_ATTRIBUTE
Request attribute to hold the currently chosen HandlerExecutionChain. |
static String |
HANDLER_MAPPING_BEAN_NAME
Well-known name for the HandlerMapping object in the bean factory for this namespace. |
static String |
LOCALE_RESOLVER_ATTRIBUTE
Request attribute to hold current locale, retrievable by views. |
static String |
LOCALE_RESOLVER_BEAN_NAME
Well-known name for the LocaleResolver object in the bean factory for this namespace. |
static String |
MULTIPART_RESOLVER_ATTRIBUTE
Request attribute to hold current multipart resolver, retrievable by views/binders. |
static String |
MULTIPART_RESOLVER_BEAN_NAME
Well-known name for the MultipartResolver object in the bean factory for this namespace. |
static String |
PAGE_NOT_FOUND_LOG_CATEGORY
Log category to use when no mapped handler is found for a request. |
protected static Log |
pageNotFoundLogger
Additional logger to use when no mapped handler is found for a request. |
static String |
THEME_RESOLVER_ATTRIBUTE
Request attribute to hold current theme, retrievable by views. |
static String |
THEME_RESOLVER_BEAN_NAME
Well-known name for the ThemeResolver object in the bean factory for this namespace. |
static String |
VIEW_RESOLVER_BEAN_NAME
Well-known name for the ViewResolver object in the bean factory for this namespace. |
static 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 |
doDispatch(HttpServletRequest request,
HttpServletResponse response)
Process the actual dispatching to the handler. |
protected void |
doService(HttpServletRequest request,
HttpServletResponse response)
Expose the DispatcherServlet-specific request attributes and delegate to doDispatch for the actual dispatching. |
protected long |
getLastModified(HttpServletRequest request)
Override HttpServlet's getLastModified method 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. |
void |
setCleanupAfterInclude(boolean cleanupAfterInclude)
Set whether to perform cleanup of request attributes after an include request, i.e. whether to reset the original state of all request attributes after the DispatcherServlet has processed within an include request. |
void |
setDetectAllHandlerExceptionResolvers(boolean detectAllHandlerExceptionResolvers)
Set whether to detect all HandlerExceptionResolver beans in this servlet's context. |
void |
setDetectAllHandlerMappings(boolean detectAllHandlerMappings)
Set whether to detect all HandlerMapping beans in this servlet's context. |
void |
setDetectAllViewResolvers(boolean detectAllViewResolvers)
Set whether to detect all ViewResolver beans in this servlet's context. |
Methods inherited from class org.springframework.web.servlet.FrameworkServlet |
createWebApplicationContext, destroy, doDelete, doGet, doHead, doPost, doPut, getContextClass, getContextConfigLocation, getNamespace, getServletContextAttributeName, getUsernameForRequest, getWebApplicationContext, initServletBean, initWebApplicationContext, isPublishContext, isPublishEvents, setContextClass, setContextConfigLocation, setNamespace, setPublishContext, setPublishEvents |
Methods inherited from class org.springframework.web.servlet.HttpServletBean |
addRequiredProperty, init, initBeanWrapper |
Methods inherited from class javax.servlet.http.HttpServlet |
doOptions, 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 |
public static final String MULTIPART_RESOLVER_BEAN_NAME
public static final String LOCALE_RESOLVER_BEAN_NAME
public static final String THEME_RESOLVER_BEAN_NAME
public static final String HANDLER_MAPPING_BEAN_NAME
setDetectAllViewResolvers(boolean)
,
Constant Field Valuespublic static final String HANDLER_EXCEPTION_RESOLVER_BEAN_NAME
setDetectAllViewResolvers(boolean)
,
Constant Field Valuespublic static final String VIEW_RESOLVER_BEAN_NAME
setDetectAllViewResolvers(boolean)
,
Constant Field Valuespublic static final String HANDLER_EXECUTION_CHAIN_ATTRIBUTE
public static final String WEB_APPLICATION_CONTEXT_ATTRIBUTE
RequestContextUtils.getWebApplicationContext(javax.servlet.ServletRequest)
public static final String MULTIPART_RESOLVER_ATTRIBUTE
RequestContextUtils.getMultipartResolver(javax.servlet.ServletRequest)
public static final String LOCALE_RESOLVER_ATTRIBUTE
RequestContextUtils.getLocaleResolver(javax.servlet.http.HttpServletRequest)
public static final String THEME_RESOLVER_ATTRIBUTE
RequestContextUtils.getThemeResolver(javax.servlet.http.HttpServletRequest)
public static final String PAGE_NOT_FOUND_LOG_CATEGORY
protected static final Log pageNotFoundLogger
Constructor Detail |
public DispatcherServlet()
Method Detail |
public void setCleanupAfterInclude(boolean cleanupAfterInclude)
Default is true, which is strongly recommended. Views should not rely on request attributes having been set by (dynamic) includes. This allows JSP views rendered by an included controller to use any model attributes, even with the same names as in the main JSP, without causing side effects. Only turn this off for special needs, for example to deliberately allow main JSPs to access attributes from JSP views rendered by an included controller.
public void setDetectAllHandlerMappings(boolean detectAllHandlerMappings)
Default is true. Turn this off if you want this servlet to use a single HandlerMapping, despite multiple HandlerMapping beans being defined in the context.
public void setDetectAllHandlerExceptionResolvers(boolean detectAllHandlerExceptionResolvers)
Default is true. Turn this off if you want this servlet to use a single HandlerExceptionResolver, despite multiple HandlerExceptionResolver beans being defined in the context.
public void setDetectAllViewResolvers(boolean detectAllViewResolvers)
Default is true. Turn this off if you want this servlet to use a single ViewResolver, despite multiple ViewResolver beans being defined in the context.
protected void initFrameworkServlet() throws ServletException, BeansException
Loads HandlerMapping and HandlerAdapter objects, and configures a ViewResolver and a LocaleResolver.
initFrameworkServlet
in class FrameworkServlet
BeansException
- if thrown by ApplicationContext methods
ServletException
- in case of an initialization exceptionprotected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception
doDispatch
for the actual dispatching.
doService
in class FrameworkServlet
request
- current HTTP requestresponse
- current HTTP response
Exception
- in case of any kind of processing failuredoDispatch(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception
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.
All HTTP methods are handled by this method. It's up to HandlerAdapters or handlers themselves to decide which methods are acceptable.
request
- current HTTP requestresponse
- current HTTP response
Exception
- in case of any kind of processing failureprotected long getLastModified(HttpServletRequest request)
getLastModified
method to evaluate
the Last-Modified value of the mapped handler.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |