Top Description Fields Constructors Methods
org.springframework.web.servlet.config.annotation

public Class DefaultServletHandlerConfigurer

extends Object
Class Inheritance
Imports
java.util.Collections, jakarta.servlet.ServletContext, org.springframework.core.Ordered, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.web.servlet.DispatcherServlet, org.springframework.web.servlet.handler.SimpleUrlHandlerMapping, org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler

Configures a request handler for serving static resources by forwarding the request to the Servlet container's "default" Servlet. This is intended to be used when the Spring MVC DispatcherServlet is mapped to "/" thus overriding the Servlet container's default handling of static resources.

Since this handler is configured at the lowest precedence, effectively it allows all other handler mappings to handle the request, and if none of them do, this handler can forward it to the "default" Servlet.

Authors
Rossen Stoyanchev, Juergen Hoeller
Since
3.1
See Also
DefaultServletHttpRequestHandler

Field Summary

Modifier and TypeField and Description
private DefaultServletHttpRequestHandler
private final ServletContext

Constructor Summary

AccessConstructor and Description
public
DefaultServletHandlerConfigurer(ServletContext
the ServletContext to use.
servletContext
)

Create a DefaultServletHandlerConfigurer instance.

Method Summary

Modifier and TypeMethod and Description
protected SimpleUrlHandlerMapping
buildHandlerMapping()

Return a handler mapping instance ordered at Ordered#LOWEST_PRECEDENCE containing the DefaultServletHttpRequestHandler instance mapped to "/**"; or null if default servlet handling was not enabled.

public void
enable()

Enable forwarding to the "default" Servlet.

public void
enable(String defaultServletName)

Enable forwarding to the "default" Servlet identified by the given name.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

handlerback to summary
private DefaultServletHttpRequestHandler handler
Annotations
@Nullable
servletContextback to summary
private final ServletContext servletContext

Constructor Detail

DefaultServletHandlerConfigurerback to summary
public DefaultServletHandlerConfigurer(ServletContext servletContext)

Create a DefaultServletHandlerConfigurer instance.

Parameters
servletContext:ServletContext

the ServletContext to use.

Method Detail

buildHandlerMappingback to summary
protected SimpleUrlHandlerMapping buildHandlerMapping()

Return a handler mapping instance ordered at Ordered#LOWEST_PRECEDENCE containing the DefaultServletHttpRequestHandler instance mapped to "/**"; or null if default servlet handling was not enabled.

Annotations
@Nullable
Since
4.3.12
enableback to summary
public void enable()

Enable forwarding to the "default" Servlet.

When this method is used the DefaultServletHttpRequestHandler will try to autodetect the "default" Servlet name. Alternatively, you can specify the name of the default Servlet via enable(String).

See Also
DefaultServletHttpRequestHandler
enableback to summary
public void enable(String defaultServletName)

Enable forwarding to the "default" Servlet identified by the given name.

This is useful when the default Servlet cannot be autodetected, for example when it has been manually configured.

See Also
DefaultServletHttpRequestHandler