Top Description Methods
org.springframework.web

public Interface HttpRequestHandler

Annotations
@FunctionalInterface
Imports
java.io.IOException, jakarta.servlet.ServletException, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse

Plain handler interface for components that process HTTP requests, analogous to a Servlet. Only declares jakarta.servlet.ServletException and java.io.IOException, to allow for usage within any jakarta.servlet.http.HttpServlet. This interface is essentially the direct equivalent of an HttpServlet, reduced to a central handle method.

The easiest way to expose an HttpRequestHandler bean in Spring style is to define it in Spring's root web application context and define an org.springframework.web.context.support.HttpRequestHandlerServlet in web.xml, pointing to the target HttpRequestHandler bean through its servlet-name which needs to match the target bean name.

Supported as a handler type within Spring's org.springframework.web.servlet.DispatcherServlet, being able to interact with the dispatcher's advanced mapping and interception facilities. This is the recommended way of exposing an HttpRequestHandler, while keeping the handler implementations free of direct dependencies on a DispatcherServlet environment.

Typically implemented to generate binary responses directly, with no separate view resource involved. This differentiates it from a org.springframework.web.servlet.mvc.Controller within Spring's Web MVC framework. The lack of a org.springframework.web.servlet.ModelAndView return value gives a clearer signature to callers other than the DispatcherServlet, indicating that there will never be a view to render.

Note that HttpRequestHandlers may optionally implement the org.springframework.web.servlet.mvc.LastModified interface, just like Controllers can, provided that they run within Spring's DispatcherServlet. However, this is usually not necessary, since HttpRequestHandlers typically only support POST requests to begin with. Alternatively, a handler may implement the "If-Modified-Since" HTTP header processing manually within its handle method.

Author
Juergen Hoeller
Since
2.0
See Also
org.springframework.web.context.support.HttpRequestHandlerServlet, org.springframework.web.servlet.DispatcherServlet, org.springframework.web.servlet.ModelAndView, org.springframework.web.servlet.mvc.Controller, org.springframework.web.servlet.mvc.LastModified, org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter

Method Summary

Modifier and TypeMethod and Description
public void
handleRequest(HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
)

Process the given request, generating a response.

Method Detail

handleRequestback to summary
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

Process the given request, generating a response.

Parameters
request:HttpServletRequest

current HTTP request

response:HttpServletResponse

current HTTP response

Exceptions
ServletException:
in case of general errors
IOException:
in case of I/O errors