DispatcherServlet
processes requests as follows:
-
The
WebApplicationContext
is looked up and bound in the request as an attribute that can be used by the controller and other process elements. By default, it is associated with theDispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE
key. -
The locale resolver is bound to the request to allow process elements to determine the locale to use when processing the request (view rendering, data preparation, and so on). If you don't need to recognize your locale, then you don't need a locale recognizer.
-
A theme resolver is bound to the request so that elements such as views can determine which theme to use. If themes are not used, then you can ignore it.
-
If a multi-part file recognizer is specified, the request will be checked for the presence of multi-part elements. If multipart elements are found, then the request is wrapped in a
MultipartHttpServletRequest
for further processing by other process elements. -
A search for a suitable handler occurs. If a handler is found, the execution chain associated with the handler (preprocessors, postprocessors, and controllers) is started to prepare the model for rendering. Additionally, for annotated controllers, the response can be rendered (within a
HandlerAdapter
) instead of returning a view. -
If a model is returned, the view is rendered. If the model is not returned (perhaps because the preprocessor or postprocessor intercepted the request, probably for security reasons), the view is not created because the request may have already been executed.
The HandlerExceptionResolver
beans declared in the WebApplicationContext
are used to recognize exceptions that are thrown when processing a request. These exception handlers allow you to customize exception handling logic.
To provide HTTP caching, handlers can use the CheckNotModified
methods from WebRequest
, as well as additional options for annotated controllers.
You can customize individual DispatcherServlet
instances by adding servlet initialization parameters (init-param
elements) to the servlet declaration in the web.xml
file. The following table lists the supported parameters:
Parameter | Explanation |
---|---|
|
A class that implements |
|
A string that is passed to the context instance (specified by |
|
Namespace |
|
Controls whether a By default, this parameter is set to Note that if default servlet processing is also configured, unresolved requests are always forwarded to the default servlet and no 404 message is generated. |
GO TO FULL VERSION