Top Description Methods
org.springframework.web.servlet

public Interface HandlerAdapter

Known Direct Implementers
org.springframework.web.servlet.function.support.HandlerFunctionAdapter, org.springframework.web.servlet.handler.SimpleServletHandlerAdapter, org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter, org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter, org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter
Imports
jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.springframework.lang.Nullable

MVC framework SPI, allowing parameterization of the core MVC workflow.

Interface that must be implemented for each handler type to handle a request. This interface is used to allow the DispatcherServlet to be indefinitely extensible. The DispatcherServlet accesses all installed handlers through this interface, meaning that it does not contain code specific to any handler type.

Note that a handler can be of type Object. This is to enable handlers from other frameworks to be integrated with this framework without custom coding, as well as to allow for annotation-driven handler objects that do not obey any specific Java interface.

This interface is not intended for application developers. It is available to handlers who want to develop their own web workflow.

Note

HandlerAdapter implementors may implement the org.springframework.core.Ordered interface to be able to specify a sorting order (and thus a priority) for getting applied by the DispatcherServlet. Non-Ordered instances get treated as the lowest priority.

Authors
Rod Johnson, Juergen Hoeller
See Also
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter, org.springframework.web.servlet.handler.SimpleServletHandlerAdapter

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the lastModified value for the given handler
getLastModified
(HttpServletRequest
current HTTP request
request
,
Object
the handler to use
handler
)
Deprecated as of 5.3.9 along with org.springframework.web.servlet.mvc.LastModified.

Same contract as for HttpServlet's getLastModified method.

public ModelAndView

Returns:

a ModelAndView object with the name of the view and the required model data, or null if the request has been handled directly
handle
(HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
,
Object
the handler to use. This object must have previously been passed to the supports method of this interface, which must have returned true.
handler
)

Use the given handler to handle this request.

public boolean

Returns:

whether this object can use the given handler
supports
(Object
the handler object to check
handler
)

Given a handler instance, return whether this HandlerAdapter can support it.

Method Detail

getLastModifiedback to summary
public long getLastModified(HttpServletRequest request, Object handler)

Deprecated

as of 5.3.9 along with org.springframework.web.servlet.mvc.LastModified.

Same contract as for HttpServlet's getLastModified method. Can simply return -1 if there's no support in the handler class.

Parameters
request:HttpServletRequest

current HTTP request

handler:Object

the handler to use

Returns:long

the lastModified value for the given handler

Annotations
@Deprecated
handleback to summary
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception

Use the given handler to handle this request. The workflow that is required may vary widely.

Parameters
request:HttpServletRequest

current HTTP request

response:HttpServletResponse

current HTTP response

handler:Object

the handler to use. This object must have previously been passed to the supports method of this interface, which must have returned true.

Returns:ModelAndView

a ModelAndView object with the name of the view and the required model data, or null if the request has been handled directly

Annotations
@Nullable
Exceptions
Exception:
in case of errors
supportsback to summary
public boolean supports(Object handler)

Given a handler instance, return whether this HandlerAdapter can support it. Typical HandlerAdapters will base the decision on the handler type. HandlerAdapters will usually only support one handler type each.

A typical implementation:

return (handler instanceof MyHandler);

Parameters
handler:Object

the handler object to check

Returns:boolean

whether this object can use the given handler