Class SimpleServletHandlerAdapter

java.lang.Object
org.springframework.web.servlet.handler.SimpleServletHandlerAdapter
All Implemented Interfaces:
HandlerAdapter

public class SimpleServletHandlerAdapter extends Object implements HandlerAdapter
Adapter to use the Servlet interface with the generic DispatcherServlet. Calls the Servlet's service method to handle a request.

Last-modified checking is not explicitly supported: This is typically handled by the Servlet implementation itself (usually deriving from the HttpServlet base class).

This adapter is not activated by default; it needs to be defined as a bean in the DispatcherServlet context. It will automatically apply to mapped handler beans that implement the Servlet interface then.

Note that Servlet instances defined as bean will not receive initialization and destruction callbacks, unless a special post-processor such as SimpleServletPostProcessor is defined in the DispatcherServlet context.

Alternatively, consider wrapping a Servlet with Spring's ServletWrappingController. This is particularly appropriate for existing Servlet classes, allowing to specify Servlet initialization parameters etc.

Since:
1.1.5
Author:
Juergen Hoeller
See Also:
  • Constructor Details

    • SimpleServletHandlerAdapter

      public SimpleServletHandlerAdapter()
  • Method Details

    • supports

      public boolean supports(Object handler)
      Description copied from interface: HandlerAdapter
      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);

      Specified by:
      supports in interface HandlerAdapter
      Parameters:
      handler - the handler object to check
      Returns:
      whether this object can use the given handler
    • handle

      @Nullable public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
      Description copied from interface: HandlerAdapter
      Use the given handler to handle this request. The workflow that is required may vary widely.
      Specified by:
      handle in interface HandlerAdapter
      Parameters:
      request - current HTTP request
      response - current HTTP response
      handler - the handler to use. This object must have previously been passed to the supports method of this interface, which must have returned true.
      Returns:
      a ModelAndView object with the name of the view and the required model data, or null if the request has been handled directly
      Throws:
      Exception - in case of errors
    • getLastModified

      public long getLastModified(HttpServletRequest request, Object handler)
      Description copied from interface: HandlerAdapter
      Same contract as for HttpServlet's getLastModified method. Can simply return -1 if there's no support in the handler class.
      Specified by:
      getLastModified in interface HandlerAdapter
      Parameters:
      request - current HTTP request
      handler - the handler to use
      Returns:
      the lastModified value for the given handler