spring-framework / org.springframework.web.servlet

Package org.springframework.web.servlet

Types

AsyncHandlerInterceptor

interface AsyncHandlerInterceptor : HandlerInterceptor

Extends HandlerInterceptor with a callback method invoked after the start of asynchronous request handling.

When a handler starts an asynchronous request, the DispatcherServlet exits without invoking postHandle and afterCompletion as it normally does for a synchronous request, since the result of request handling (e.g. ModelAndView) is likely not yet ready and will be produced concurrently from another thread. In such scenarios, #afterConcurrentHandlingStarted is invoked instead, allowing implementations to perform tasks such as cleaning up thread-bound attributes before releasing the thread to the Servlet container.

When asynchronous handling completes, the request is dispatched to the container for further processing. At this stage the DispatcherServlet invokes preHandle, postHandle, and afterCompletion. To distinguish between the initial request and the subsequent dispatch after asynchronous handling completes, interceptors can check whether the javax.servlet.DispatcherType of javax.servlet.ServletRequest is "REQUEST" or "ASYNC".

Note that HandlerInterceptor implementations may need to do work when an async request times out or completes with a network error. For such cases the Servlet container does not dispatch and therefore the postHandle and afterCompletion methods will not be invoked. Instead, interceptors can register to track an asynchronous request through the registerCallbackInterceptor and registerDeferredResultInterceptor methods on org.springframework.web.context.request.async.WebAsyncManager. This can be done proactively on every request from preHandle regardless of whether async request processing will start.

RequestToViewNameTranslator

interface RequestToViewNameTranslator

Strategy interface for translating an incoming javax.servlet.http.HttpServletRequest into a logical view name when no view name is explicitly supplied.

SmartView

interface SmartView : View

Provides additional information about a View such as whether it performs redirects.

Exceptions

ModelAndViewDefiningException

open class ModelAndViewDefiningException : ServletException

Exception to be thrown on error conditions that should forward to a specific view with a specific model.

Can be thrown at any time during handler processing. This includes any template methods of pre-built controllers. For example, a form controller might abort to a specific error page if certain parameters do not allow to proceed with the normal workflow.