Class DefaultServletHttpRequestHandler
- java.lang.Object
- org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler
- All Implemented Interfaces:
Aware,ServletContextAware,HttpRequestHandler
public class DefaultServletHttpRequestHandler extends Object implements HttpRequestHandler, ServletContextAware
AnHttpRequestHandlerfor serving static files using the Servlet container's "default" Servlet.This handler is intended to be used with a "/*" mapping when the
DispatcherServletis 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
RequestDispatcherobtained via the name specified through the"defaultServletName" property. In most cases, thedefaultServletNamedoes 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, thedefaultServletNamewill need to be set explicitly.- Since:
- 3.0.4
- Author:
- Jeremy Grelle, Juergen Hoeller
Constructor Summary
Constructors Constructor Description DefaultServletHttpRequestHandler()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidhandleRequest(HttpServletRequest request, HttpServletResponse response)Process the given request, generating a response.voidsetDefaultServletName(String defaultServletName)Set the name of the default Servlet to be forwarded to for static resource requests.voidsetServletContext(ServletContext servletContext)If thedefaultServletNameproperty has not been explicitly set, attempts to locate the default Servlet using the known common container-specific names.
Constructor Detail
DefaultServletHttpRequestHandler
public DefaultServletHttpRequestHandler()
Method Detail
setDefaultServletName
public void setDefaultServletName(String defaultServletName)
Set the name of the default Servlet to be forwarded to for static resource requests.
setServletContext
public void setServletContext(ServletContext servletContext)
If thedefaultServletNameproperty has not been explicitly set, attempts to locate the default Servlet using the known common container-specific names.- Specified by:
setServletContextin interfaceServletContextAware- Parameters:
servletContext- ServletContext object to be used by this object- See Also:
InitializingBean.afterPropertiesSet(),ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)
handleRequest
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
Description copied from interface:HttpRequestHandlerProcess the given request, generating a response.- Specified by:
handleRequestin interfaceHttpRequestHandler- Parameters:
request- current HTTP requestresponse- current HTTP response- Throws:
ServletException- in case of general errorsIOException- in case of I/O errors