public class DispatcherServlet extends FrameworkServlet
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:
HandlerMapping
implementation - pre-built or provided as part
of an application - to control the routing of requests to handler objects. Default is
BeanNameUrlHandlerMapping
and
RequestMappingHandlerMapping
.
HandlerMapping objects can be defined as beans in the servlet's application context,
implementing the HandlerMapping interface, overriding the default HandlerMapping if
present. HandlerMappings can be given any bean name (they are tested by type).
HandlerAdapter
; this allows for using any handler interface.
Default adapters are HttpRequestHandlerAdapter
,
SimpleControllerHandlerAdapter
, for Spring's
HttpRequestHandler
and
Controller
interfaces, respectively. A default
RequestMappingHandlerAdapter
will be registered as well. HandlerAdapter objects can be added as beans in the
application context, overriding the default HandlerAdapters. Like HandlerMappings,
HandlerAdapters can be given any bean name (they are tested by type).
HandlerExceptionResolver
, for example mapping certain exceptions to error pages.
Default are
ExceptionHandlerExceptionResolver
,
ResponseStatusExceptionResolver
, and
DefaultHandlerExceptionResolver
.
These HandlerExceptionResolvers can be overridden through the application context.
HandlerExceptionResolver can be given any bean name (they are tested by type).
ViewResolver
implementation, resolving symbolic view names into View objects. Default is
InternalResourceViewResolver
.
ViewResolver objects can be added as beans in the application context, overriding the
default ViewResolver. ViewResolvers can be given any bean name (they are tested by type).
View
or view name is not supplied by the user, then the configured
RequestToViewNameTranslator
will translate the current request into a view name.
The corresponding bean name is "viewNameTranslator"; the default is
DefaultRequestToViewNameTranslator
.
MultipartResolver
implementation.
Implementations for Apache Commons FileUpload and Servlet 3 are included; the typical
choice is CommonsMultipartResolver
.
The MultipartResolver bean name is "multipartResolver"; default is none.
LocaleResolver
.
Out-of-the-box implementations work via HTTP accept header, cookie, or session.
The LocaleResolver bean name is "localeResolver"; default is
AcceptHeaderLocaleResolver
.
ThemeResolver
.
Implementations for a fixed theme and for cookie and session storage are included.
The ThemeResolver bean name is "themeResolver"; default is
FixedThemeResolver
.
NOTE: The @RequestMapping
annotation will only be processed if a
corresponding HandlerMapping
(for type-level annotations) and/or
HandlerAdapter
(for method-level annotations) is present in the dispatcher.
This is the case by default. However, if you are defining custom HandlerMappings
or HandlerAdapters
, then you need to make sure that a corresponding custom
RequestMappingHandlerMapping
and/or RequestMappingHandlerAdapter
is defined as well - provided that you intend to use @RequestMapping
.
A web application can define any number of DispatcherServlets.
Each servlet will operate in its own namespace, loading its own application context
with mappings, handlers, etc. Only the root application context as loaded by
ContextLoaderListener
, if any, will be shared.
As of Spring 3.1, DispatcherServlet
may now be injected with a web
application context, rather than creating its own internally. This is useful in Servlet
3.0+ environments, which support programmatic registration of servlet instances.
See the DispatcherServlet(WebApplicationContext)
javadoc for details.
HttpRequestHandler
,
Controller
,
ContextLoaderListener
Modifier and Type | Field and Description |
---|---|
private boolean |
cleanupAfterInclude
Perform cleanup of request attributes after include request?
|
private static java.lang.String |
DEFAULT_STRATEGIES_PATH
Name of the class path resource (relative to the DispatcherServlet class)
that defines DispatcherServlet's default strategy names.
|
private static java.util.Properties |
defaultStrategies |
private boolean |
detectAllHandlerAdapters
Detect all HandlerAdapters or just expect "handlerAdapter" bean?
|
private boolean |
detectAllHandlerExceptionResolvers
Detect all HandlerExceptionResolvers or just expect "handlerExceptionResolver" bean?
|
private boolean |
detectAllHandlerMappings
Detect all HandlerMappings or just expect "handlerMapping" bean?
|
private boolean |
detectAllViewResolvers
Detect all ViewResolvers or just expect "viewResolver" bean?
|
static java.lang.String |
EXCEPTION_ATTRIBUTE
Name of request attribute that exposes an Exception resolved with an
HandlerExceptionResolver but where no view was rendered
(e.g. |
static java.lang.String |
FLASH_MAP_MANAGER_ATTRIBUTE
Name of request attribute that holds the
FlashMapManager . |
static java.lang.String |
FLASH_MAP_MANAGER_BEAN_NAME
Well-known name for the FlashMapManager object in the bean factory for this namespace.
|
private FlashMapManager |
flashMapManager
FlashMapManager used by this servlet
|
static java.lang.String |
HANDLER_ADAPTER_BEAN_NAME
Well-known name for the HandlerAdapter object in the bean factory for this namespace.
|
static java.lang.String |
HANDLER_EXCEPTION_RESOLVER_BEAN_NAME
Well-known name for the HandlerExceptionResolver object in the bean factory for this namespace.
|
static java.lang.String |
HANDLER_MAPPING_BEAN_NAME
Well-known name for the HandlerMapping object in the bean factory for this namespace.
|
private java.util.List<HandlerAdapter> |
handlerAdapters
List of HandlerAdapters used by this servlet
|
private java.util.List<HandlerExceptionResolver> |
handlerExceptionResolvers
List of HandlerExceptionResolvers used by this servlet
|
private java.util.List<HandlerMapping> |
handlerMappings
List of HandlerMappings used by this servlet
|
static java.lang.String |
INPUT_FLASH_MAP_ATTRIBUTE
Name of request attribute that holds a read-only
Map<String,?>
with "input" flash attributes saved by a previous request, if any. |
static java.lang.String |
LOCALE_RESOLVER_ATTRIBUTE
Request attribute to hold the current LocaleResolver, 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.
|
private LocaleResolver |
localeResolver
LocaleResolver used by this servlet
|
static java.lang.String |
MULTIPART_RESOLVER_BEAN_NAME
Well-known name for the MultipartResolver object in the bean factory for this namespace.
|
private MultipartResolver |
multipartResolver
MultipartResolver used by this servlet
|
static java.lang.String |
OUTPUT_FLASH_MAP_ATTRIBUTE
Name of request attribute that holds the "output"
FlashMap with
attributes to save for a subsequent request. |
static java.lang.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 java.lang.String |
REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME
Well-known name for the RequestToViewNameTranslator object in the bean factory for this namespace.
|
static java.lang.String |
THEME_RESOLVER_ATTRIBUTE
Request attribute to hold the current ThemeResolver, 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 |
THEME_SOURCE_ATTRIBUTE
Request attribute to hold the current ThemeSource, retrievable by views.
|
private ThemeResolver |
themeResolver
ThemeResolver used by this servlet
|
private boolean |
throwExceptionIfNoHandlerFound
Throw a NoHandlerFoundException if no Handler was found to process this request?
|
static java.lang.String |
VIEW_RESOLVER_BEAN_NAME
Well-known name for the ViewResolver object in the bean factory for this namespace.
|
private RequestToViewNameTranslator |
viewNameTranslator
RequestToViewNameTranslator used by this servlet
|
private java.util.List<ViewResolver> |
viewResolvers
List of ViewResolvers used by this servlet
|
static java.lang.String |
WEB_APPLICATION_CONTEXT_ATTRIBUTE
Request attribute to hold the current web application context.
|
DEFAULT_CONTEXT_CLASS, DEFAULT_NAMESPACE_SUFFIX, SERVLET_CONTEXT_PREFIX
logger
Constructor and Description |
---|
DispatcherServlet()
Create a new
DispatcherServlet that will create its own internal web
application context based on defaults and values provided through servlet
init-params. |
DispatcherServlet(WebApplicationContext webApplicationContext)
Create a new
DispatcherServlet with the given web application context. |
Modifier and Type | Method and Description |
---|---|
private void |
applyDefaultViewName(HttpServletRequest request,
ModelAndView mv)
Do we need view name translation?
|
protected LocaleContext |
buildLocaleContext(HttpServletRequest request)
Build a LocaleContext for the given request, exposing the request's primary locale as current locale.
|
protected HttpServletRequest |
checkMultipart(HttpServletRequest request)
Convert the request into a multipart request, and make multipart resolver available.
|
protected void |
cleanupMultipart(HttpServletRequest request)
Clean up any resources used by the given multipart request (if any).
|
protected java.lang.Object |
createDefaultStrategy(ApplicationContext context,
java.lang.Class<?> clazz)
Create a default strategy.
|
protected void |
doDispatch(HttpServletRequest request,
HttpServletResponse response)
Process the actual dispatching to the handler.
|
protected void |
doService(HttpServletRequest request,
HttpServletResponse response)
Exposes the DispatcherServlet-specific request attributes and delegates to
doDispatch(HttpServletRequest, HttpServletResponse)
for the actual dispatching. |
protected <T> java.util.List<T> |
getDefaultStrategies(ApplicationContext context,
java.lang.Class<T> strategyInterface)
Create a List of default strategy objects for the given strategy interface.
|
protected <T> T |
getDefaultStrategy(ApplicationContext context,
java.lang.Class<T> strategyInterface)
Return the default strategy object for the given strategy interface.
|
protected java.lang.String |
getDefaultViewName(HttpServletRequest request)
Translate the supplied request into a default view name.
|
protected HandlerExecutionChain |
getHandler(HttpServletRequest request)
Return the HandlerExecutionChain for this request.
|
protected HandlerAdapter |
getHandlerAdapter(java.lang.Object handler)
Return the HandlerAdapter for this handler object.
|
MultipartResolver |
getMultipartResolver()
Obtain this servlet's MultipartResolver, if any.
|
private static java.lang.String |
getRequestUri(HttpServletRequest request) |
ThemeSource |
getThemeSource()
Return this servlet's ThemeSource, if any; else return
null . |
private boolean |
hasMultipartException(HttpServletRequest request)
Check "javax.servlet.error.exception" attribute for a multipart exception.
|
private void |
initFlashMapManager(ApplicationContext context)
Initialize the
FlashMapManager used by this servlet instance. |
private void |
initHandlerAdapters(ApplicationContext context)
Initialize the HandlerAdapters used by this class.
|
private void |
initHandlerExceptionResolvers(ApplicationContext context)
Initialize the HandlerExceptionResolver used by this class.
|
private void |
initHandlerMappings(ApplicationContext context)
Initialize the HandlerMappings used by this class.
|
private void |
initLocaleResolver(ApplicationContext context)
Initialize the LocaleResolver used by this class.
|
private void |
initMultipartResolver(ApplicationContext context)
Initialize the MultipartResolver used by this class.
|
private void |
initRequestToViewNameTranslator(ApplicationContext context)
Initialize the RequestToViewNameTranslator used by this servlet instance.
|
protected void |
initStrategies(ApplicationContext context)
Initialize the strategy objects that this servlet uses.
|
private void |
initThemeResolver(ApplicationContext context)
Initialize the ThemeResolver used by this class.
|
private void |
initViewResolvers(ApplicationContext context)
Initialize the ViewResolvers used by this class.
|
protected void |
noHandlerFound(HttpServletRequest request,
HttpServletResponse response)
No handler found -> set appropriate HTTP response status.
|
protected void |
onRefresh(ApplicationContext context)
This implementation calls
initStrategies(org.springframework.context.ApplicationContext) . |
private void |
processDispatchResult(HttpServletRequest request,
HttpServletResponse response,
HandlerExecutionChain mappedHandler,
ModelAndView mv,
java.lang.Exception exception)
Handle the result of handler selection and handler invocation, which is
either a ModelAndView or an Exception to be resolved to a ModelAndView.
|
protected ModelAndView |
processHandlerException(HttpServletRequest request,
HttpServletResponse response,
java.lang.Object handler,
java.lang.Exception ex)
Determine an error ModelAndView via the registered HandlerExceptionResolvers.
|
protected void |
render(ModelAndView mv,
HttpServletRequest request,
HttpServletResponse response)
Render the given ModelAndView.
|
protected View |
resolveViewName(java.lang.String viewName,
java.util.Map<java.lang.String,java.lang.Object> model,
java.util.Locale locale,
HttpServletRequest request)
Resolve the given view name into a View object (to be rendered).
|
private void |
restoreAttributesAfterInclude(HttpServletRequest request,
java.util.Map<?,?> attributesSnapshot)
Restore the request attributes after an include.
|
void |
setCleanupAfterInclude(boolean cleanupAfterInclude)
Set whether to perform cleanup of request attributes after an include request, that is,
whether to reset the original state of all request attributes after the DispatcherServlet
has processed within an include request.
|
void |
setDetectAllHandlerAdapters(boolean detectAllHandlerAdapters)
Set whether to detect all HandlerAdapter beans in this servlet's context.
|
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.
|
void |
setThrowExceptionIfNoHandlerFound(boolean throwExceptionIfNoHandlerFound)
Set whether to throw a NoHandlerFoundException when no Handler was found for this request.
|
private void |
triggerAfterCompletion(HttpServletRequest request,
HttpServletResponse response,
HandlerExecutionChain mappedHandler,
java.lang.Exception ex) |
applyInitializers, buildRequestAttributes, configureAndRefreshWebApplicationContext, createWebApplicationContext, createWebApplicationContext, destroy, doDelete, doGet, doOptions, doPost, doPut, doTrace, findWebApplicationContext, getContextAttribute, getContextClass, getContextConfigLocation, getContextId, getNamespace, getServletContextAttributeName, getUsernameForRequest, getWebApplicationContext, initFrameworkServlet, initServletBean, initWebApplicationContext, onApplicationEvent, postProcessWebApplicationContext, processRequest, refresh, service, setApplicationContext, setContextAttribute, setContextClass, setContextConfigLocation, setContextId, setContextInitializerClasses, setContextInitializers, setDispatchOptionsRequest, setDispatchTraceRequest, setNamespace, setPublishContext, setPublishEvents, setThreadContextInheritable
addRequiredProperty, createEnvironment, getEnvironment, getServletContext, getServletName, init, initBeanWrapper, setEnvironment
public static final java.lang.String MULTIPART_RESOLVER_BEAN_NAME
public static final java.lang.String LOCALE_RESOLVER_BEAN_NAME
public static final java.lang.String THEME_RESOLVER_BEAN_NAME
public static final java.lang.String HANDLER_MAPPING_BEAN_NAME
public static final java.lang.String HANDLER_ADAPTER_BEAN_NAME
public static final java.lang.String HANDLER_EXCEPTION_RESOLVER_BEAN_NAME
public static final java.lang.String REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME
public static final java.lang.String VIEW_RESOLVER_BEAN_NAME
public static final java.lang.String FLASH_MAP_MANAGER_BEAN_NAME
public static final java.lang.String WEB_APPLICATION_CONTEXT_ATTRIBUTE
public static final java.lang.String LOCALE_RESOLVER_ATTRIBUTE
public static final java.lang.String THEME_RESOLVER_ATTRIBUTE
public static final java.lang.String THEME_SOURCE_ATTRIBUTE
public static final java.lang.String INPUT_FLASH_MAP_ATTRIBUTE
Map<String,?>
with "input" flash attributes saved by a previous request, if any.public static final java.lang.String OUTPUT_FLASH_MAP_ATTRIBUTE
FlashMap
with
attributes to save for a subsequent request.public static final java.lang.String FLASH_MAP_MANAGER_ATTRIBUTE
FlashMapManager
.public static final java.lang.String EXCEPTION_ATTRIBUTE
HandlerExceptionResolver
but where no view was rendered
(e.g. setting the status code).public static final java.lang.String PAGE_NOT_FOUND_LOG_CATEGORY
private static final java.lang.String DEFAULT_STRATEGIES_PATH
protected static final Log pageNotFoundLogger
private static final java.util.Properties defaultStrategies
private boolean detectAllHandlerMappings
private boolean detectAllHandlerAdapters
private boolean detectAllHandlerExceptionResolvers
private boolean detectAllViewResolvers
private boolean throwExceptionIfNoHandlerFound
private boolean cleanupAfterInclude
private MultipartResolver multipartResolver
private LocaleResolver localeResolver
private ThemeResolver themeResolver
private java.util.List<HandlerMapping> handlerMappings
private java.util.List<HandlerAdapter> handlerAdapters
private java.util.List<HandlerExceptionResolver> handlerExceptionResolvers
private RequestToViewNameTranslator viewNameTranslator
private FlashMapManager flashMapManager
private java.util.List<ViewResolver> viewResolvers
public DispatcherServlet()
DispatcherServlet
that will create its own internal web
application context based on defaults and values provided through servlet
init-params. Typically used in Servlet 2.5 or earlier environments, where the only
option for servlet registration is through web.xml
which requires the use
of a no-arg constructor.
Calling FrameworkServlet.setContextConfigLocation(java.lang.String)
(init-param 'contextConfigLocation')
will dictate which XML files will be loaded by the
default XmlWebApplicationContext
Calling FrameworkServlet.setContextClass(java.lang.Class<?>)
(init-param 'contextClass') overrides the
default XmlWebApplicationContext
and allows for specifying an alternative class,
such as AnnotationConfigWebApplicationContext
.
Calling FrameworkServlet.setContextInitializerClasses(java.lang.String)
(init-param 'contextInitializerClasses')
indicates which ApplicationContextInitializer
classes should be used to
further configure the internal application context prior to refresh().
DispatcherServlet(WebApplicationContext)
public DispatcherServlet(WebApplicationContext webApplicationContext)
DispatcherServlet
with the given web application context. This
constructor is useful in Servlet 3.0+ environments where instance-based registration
of servlets is possible through the ServletContext#addServlet
API.
Using this constructor indicates that the following properties / init-params will be ignored:
FrameworkServlet.setContextClass(Class)
/ 'contextClass'FrameworkServlet.setContextConfigLocation(String)
/ 'contextConfigLocation'FrameworkServlet.setContextAttribute(String)
/ 'contextAttribute'FrameworkServlet.setNamespace(String)
/ 'namespace'The given web application context may or may not yet be refreshed. If it has not already been refreshed (the recommended approach), then the following will occur:
ServletContext
and ServletConfig
objects will be delegated to
the application contextFrameworkServlet.postProcessWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext)
will be calledApplicationContextInitializer
s specified through the
"contextInitializerClasses" init-param or through the FrameworkServlet.setContextInitializers(org.springframework.context.ApplicationContextInitializer<?>...)
property will be applied.refresh()
will be called if the
context implements ConfigurableApplicationContext
See WebApplicationInitializer
for usage examples.
webApplicationContext
- the context to useFrameworkServlet.initWebApplicationContext()
,
FrameworkServlet.configureAndRefreshWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext)
,
WebApplicationInitializer
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 setDetectAllHandlerAdapters(boolean detectAllHandlerAdapters)
Default is "true". Turn this off if you want this servlet to use a single HandlerAdapter, despite multiple HandlerAdapter 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.
public void setThrowExceptionIfNoHandlerFound(boolean throwExceptionIfNoHandlerFound)
@ExceptionHandler
controller method.
Note that if DefaultServletHttpRequestHandler
is used, then requests will always be forwarded to the default servlet and a
NoHandlerFoundException would never be thrown in that case.
Default is "false", meaning the DispatcherServlet sends a NOT_FOUND error through the Servlet response.
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.
protected void onRefresh(ApplicationContext context)
initStrategies(org.springframework.context.ApplicationContext)
.onRefresh
in class FrameworkServlet
context
- the current WebApplicationContextFrameworkServlet.refresh()
protected void initStrategies(ApplicationContext context)
May be overridden in subclasses in order to initialize further strategy objects.
private void initMultipartResolver(ApplicationContext context)
If no bean is defined with the given name in the BeanFactory for this namespace, no multipart handling is provided.
private void initLocaleResolver(ApplicationContext context)
If no bean is defined with the given name in the BeanFactory for this namespace, we default to AcceptHeaderLocaleResolver.
private void initThemeResolver(ApplicationContext context)
If no bean is defined with the given name in the BeanFactory for this namespace, we default to a FixedThemeResolver.
private void initHandlerMappings(ApplicationContext context)
If no HandlerMapping beans are defined in the BeanFactory for this namespace, we default to BeanNameUrlHandlerMapping.
private void initHandlerAdapters(ApplicationContext context)
If no HandlerAdapter beans are defined in the BeanFactory for this namespace, we default to SimpleControllerHandlerAdapter.
private void initHandlerExceptionResolvers(ApplicationContext context)
If no bean is defined with the given name in the BeanFactory for this namespace, we default to no exception resolver.
private void initRequestToViewNameTranslator(ApplicationContext context)
If no implementation is configured then we default to DefaultRequestToViewNameTranslator.
private void initViewResolvers(ApplicationContext context)
If no ViewResolver beans are defined in the BeanFactory for this namespace, we default to InternalResourceViewResolver.
private void initFlashMapManager(ApplicationContext context)
FlashMapManager
used by this servlet instance.
If no implementation is configured then we default to
org.springframework.web.servlet.support.DefaultFlashMapManager
.
public final ThemeSource getThemeSource()
null
.
Default is to return the WebApplicationContext as ThemeSource, provided that it implements the ThemeSource interface.
FrameworkServlet.getWebApplicationContext()
public final MultipartResolver getMultipartResolver()
null
if none
(indicating that no multipart support is available)protected <T> T getDefaultStrategy(ApplicationContext context, java.lang.Class<T> strategyInterface)
The default implementation delegates to getDefaultStrategies(org.springframework.context.ApplicationContext, java.lang.Class<T>)
,
expecting a single object in the list.
context
- the current WebApplicationContextstrategyInterface
- the strategy interfacegetDefaultStrategies(org.springframework.context.ApplicationContext, java.lang.Class<T>)
protected <T> java.util.List<T> getDefaultStrategies(ApplicationContext context, java.lang.Class<T> strategyInterface)
The default implementation uses the "DispatcherServlet.properties" file (in the same package as the DispatcherServlet class) to determine the class names. It instantiates the strategy objects through the context's BeanFactory.
context
- the current WebApplicationContextstrategyInterface
- the strategy interfaceprotected java.lang.Object createDefaultStrategy(ApplicationContext context, java.lang.Class<?> clazz)
The default implementation uses
AutowireCapableBeanFactory.createBean(java.lang.Class<T>)
.
context
- the current WebApplicationContextclazz
- the strategy implementation class to instantiateApplicationContext.getAutowireCapableBeanFactory()
,
AutowireCapableBeanFactory.createBean(java.lang.Class<T>)
protected void doService(HttpServletRequest request, HttpServletResponse response) throws java.lang.Exception
doDispatch(HttpServletRequest, HttpServletResponse)
for the actual dispatching.doService
in class FrameworkServlet
request
- current HTTP requestresponse
- current HTTP responsejava.lang.Exception
- in case of any kind of processing failurejavax.servlet.http.HttpServlet#doGet
,
javax.servlet.http.HttpServlet#doPost
protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws java.lang.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 responsejava.lang.Exception
- in case of any kind of processing failureprivate void applyDefaultViewName(HttpServletRequest request, ModelAndView mv) throws java.lang.Exception
java.lang.Exception
private void processDispatchResult(HttpServletRequest request, HttpServletResponse response, HandlerExecutionChain mappedHandler, ModelAndView mv, java.lang.Exception exception) throws java.lang.Exception
java.lang.Exception
protected LocaleContext buildLocaleContext(HttpServletRequest request)
The default implementation uses the dispatcher's LocaleResolver to obtain the current locale, which might change during a request.
buildLocaleContext
in class FrameworkServlet
request
- current HTTP requestLocaleContextHolder.setLocaleContext(org.springframework.context.i18n.LocaleContext)
protected HttpServletRequest checkMultipart(HttpServletRequest request) throws MultipartException
If no multipart resolver is set, simply use the existing request.
request
- current HTTP requestMultipartException
MultipartResolver.resolveMultipart(HttpServletRequest)
private boolean hasMultipartException(HttpServletRequest request)
protected void cleanupMultipart(HttpServletRequest request)
request
- current HTTP requestMultipartResolver.cleanupMultipart(org.springframework.web.multipart.MultipartHttpServletRequest)
protected HandlerExecutionChain getHandler(HttpServletRequest request) throws java.lang.Exception
Tries all handler mappings in order.
request
- current HTTP requestnull
if no handler could be foundjava.lang.Exception
protected void noHandlerFound(HttpServletRequest request, HttpServletResponse response) throws java.lang.Exception
request
- current HTTP requestresponse
- current HTTP responsejava.lang.Exception
- if preparing the response failedprotected HandlerAdapter getHandlerAdapter(java.lang.Object handler) throws ServletException
handler
- the handler object to find an adapter forServletException
- if no HandlerAdapter can be found for the handler. This is a fatal error.protected ModelAndView processHandlerException(HttpServletRequest request, HttpServletResponse response, java.lang.Object handler, java.lang.Exception ex) throws java.lang.Exception
request
- current HTTP requestresponse
- current HTTP responsehandler
- the executed handler, or null
if none chosen at the time of the exception
(for example, if multipart resolution failed)ex
- the exception that got thrown during handler executionjava.lang.Exception
- if no error ModelAndView foundprotected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response) throws java.lang.Exception
This is the last stage in handling a request. It may involve resolving the view by name.
mv
- the ModelAndView to renderrequest
- current HTTP servlet requestresponse
- current HTTP servlet responseServletException
- if view is missing or cannot be resolvedjava.lang.Exception
- if there's a problem rendering the viewprotected java.lang.String getDefaultViewName(HttpServletRequest request) throws java.lang.Exception
request
- current HTTP servlet requestnull
if no default found)java.lang.Exception
- if view name translation failedprotected View resolveViewName(java.lang.String viewName, java.util.Map<java.lang.String,java.lang.Object> model, java.util.Locale locale, HttpServletRequest request) throws java.lang.Exception
The default implementations asks all ViewResolvers of this dispatcher. Can be overridden for custom resolution strategies, potentially based on specific model attributes or request parameters.
viewName
- the name of the view to resolvemodel
- the model to be passed to the viewlocale
- the current localerequest
- current HTTP servlet requestnull
if none foundjava.lang.Exception
- if the view cannot be resolved
(typically in case of problems creating an actual View object)ViewResolver.resolveViewName(java.lang.String, java.util.Locale)
private void triggerAfterCompletion(HttpServletRequest request, HttpServletResponse response, HandlerExecutionChain mappedHandler, java.lang.Exception ex) throws java.lang.Exception
java.lang.Exception
private void restoreAttributesAfterInclude(HttpServletRequest request, java.util.Map<?,?> attributesSnapshot)
request
- current HTTP requestattributesSnapshot
- the snapshot of the request attributes before the includeprivate static java.lang.String getRequestUri(HttpServletRequest request)