Top Description Fields Constructors Methods
org.springframework.web.servlet.resource

public Class DefaultServletHttpRequestHandler

extends Object
implements HttpRequestHandler, ServletContextAware
Class Inheritance
All Implemented Interfaces
org.springframework.web.context.ServletContextAware, org.springframework.beans.factory.Aware, org.springframework.web.HttpRequestHandler
Imports
java.io.IOException, jakarta.servlet.DispatcherType, .RequestDispatcher, .ServletContext, .ServletException, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils, org.springframework.web.HttpRequestHandler, org.springframework.web.context.ServletContextAware

An HttpRequestHandler for serving static files using the Servlet container's "default" Servlet.

This handler is intended to be used with a "/*" mapping when the DispatcherServlet is mapped to "/", thus overriding the Servlet container's default handling of static resources. The mapping to this handler should generally be ordered as the last in the chain so that it will only execute when no other more specific mappings (i.e., to controllers) can be matched.

Requests are handled by forwarding through the RequestDispatcher obtained via the name specified through the "defaultServletName" property. In most cases, the defaultServletName does not need to be set explicitly, as the handler checks at initialization time for the presence of the default Servlet of well-known containers such as Tomcat, Jetty, Resin, WebLogic and WebSphere. However, when running in a container where the default Servlet's name is not known, or where it has been customized via server configuration, the defaultServletName will need to be set explicitly.

Authors
Jeremy Grelle, Juergen Hoeller
Since
3.0.4

Field Summary

Modifier and TypeField and Description
private static final String
COMMON_DEFAULT_SERVLET_NAME

Default Servlet name used by Tomcat, Jetty, JBoss, and GlassFish.

private String
private static final String
GAE_DEFAULT_SERVLET_NAME

Default Servlet name used by Google App Engine.

private static final String
RESIN_DEFAULT_SERVLET_NAME

Default Servlet name used by Resin.

private ServletContext
private static final String
WEBLOGIC_DEFAULT_SERVLET_NAME

Default Servlet name used by WebLogic.

private static final String
WEBSPHERE_DEFAULT_SERVLET_NAME

Default Servlet name used by WebSphere.

Constructor Summary

AccessConstructor and Description
public

Method Summary

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

Implements org.springframework.web.HttpRequestHandler.handleRequest.

Process the given request, generating a response.

public void
setDefaultServletName(String defaultServletName)

Set the name of the default Servlet to be forwarded to for static resource requests.

public void
setServletContext(ServletContext
the ServletContext object to be used by this object
servletContext
)

Implements org.springframework.web.context.ServletContextAware.setServletContext.

If the defaultServletName property has not been explicitly set, attempts to locate the default Servlet using the known common container-specific names.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

COMMON_DEFAULT_SERVLET_NAMEback to summary
private static final String COMMON_DEFAULT_SERVLET_NAME

Default Servlet name used by Tomcat, Jetty, JBoss, and GlassFish.

defaultServletNameback to summary
private String defaultServletName
Annotations
@Nullable
GAE_DEFAULT_SERVLET_NAMEback to summary
private static final String GAE_DEFAULT_SERVLET_NAME

Default Servlet name used by Google App Engine.

RESIN_DEFAULT_SERVLET_NAMEback to summary
private static final String RESIN_DEFAULT_SERVLET_NAME

Default Servlet name used by Resin.

servletContextback to summary
private ServletContext servletContext
Annotations
@Nullable
WEBLOGIC_DEFAULT_SERVLET_NAMEback to summary
private static final String WEBLOGIC_DEFAULT_SERVLET_NAME

Default Servlet name used by WebLogic.

WEBSPHERE_DEFAULT_SERVLET_NAMEback to summary
private static final String WEBSPHERE_DEFAULT_SERVLET_NAME

Default Servlet name used by WebSphere.

Constructor Detail

DefaultServletHttpRequestHandlerback to summary
public DefaultServletHttpRequestHandler()

Method Detail

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

Implements org.springframework.web.HttpRequestHandler.handleRequest.

Doc from org.springframework.web.HttpRequestHandler.handleRequest.

Process the given request, generating a response.

Parameters
request:HttpServletRequest

current HTTP request

response:HttpServletResponse

current HTTP response

Annotations
@Override
Exceptions
ServletException:
in case of general errors
IOException:
in case of I/O errors
setDefaultServletNameback to summary
public void setDefaultServletName(String defaultServletName)

Set the name of the default Servlet to be forwarded to for static resource requests.

setServletContextback to summary
public void setServletContext(ServletContext servletContext)

Implements org.springframework.web.context.ServletContextAware.setServletContext.

If the defaultServletName property has not been explicitly set, attempts to locate the default Servlet using the known common container-specific names.

Parameters
servletContext:ServletContext

Doc from org.springframework.web.context.ServletContextAware.setServletContext.

the ServletContext object to be used by this object

Annotations
@Override