org.springframework.web.servlet.resource
Class DefaultServletHttpRequestHandler

java.lang.Object
  extended by org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler
All Implemented Interfaces:
Aware, ServletContextAware, HttpRequestHandler

public class DefaultServletHttpRequestHandler
extends java.lang.Object
implements HttpRequestHandler, 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.

Since:
3.0.4
Author:
Jeremy Grelle, Juergen Hoeller

Field Summary
private static java.lang.String COMMON_DEFAULT_SERVLET_NAME
          Default Servlet name used by Tomcat, Jetty, JBoss, and GlassFish
private  java.lang.String defaultServletName
           
private static java.lang.String GAE_DEFAULT_SERVLET_NAME
          Default Servlet name used by Google App Engine
private static java.lang.String RESIN_DEFAULT_SERVLET_NAME
          Default Servlet name used by Resin
private  ServletContext servletContext
           
private static java.lang.String WEBLOGIC_DEFAULT_SERVLET_NAME
          Default Servlet name used by WebLogic
private static java.lang.String WEBSPHERE_DEFAULT_SERVLET_NAME
          Default Servlet name used by WebSphere
 
Constructor Summary
DefaultServletHttpRequestHandler()
           
 
Method Summary
 void handleRequest(HttpServletRequest request, HttpServletResponse response)
          Process the given request, generating a response.
 void setDefaultServletName(java.lang.String defaultServletName)
          Set the name of the default Servlet to be forwarded to for static resource requests.
 void setServletContext(ServletContext servletContext)
          If the defaultServletName property has not been explicitly set, attempts to locate the default Servlet using the known common container-specific names.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMON_DEFAULT_SERVLET_NAME

private static final java.lang.String COMMON_DEFAULT_SERVLET_NAME
Default Servlet name used by Tomcat, Jetty, JBoss, and GlassFish

See Also:
Constant Field Values

GAE_DEFAULT_SERVLET_NAME

private static final java.lang.String GAE_DEFAULT_SERVLET_NAME
Default Servlet name used by Google App Engine

See Also:
Constant Field Values

RESIN_DEFAULT_SERVLET_NAME

private static final java.lang.String RESIN_DEFAULT_SERVLET_NAME
Default Servlet name used by Resin

See Also:
Constant Field Values

WEBLOGIC_DEFAULT_SERVLET_NAME

private static final java.lang.String WEBLOGIC_DEFAULT_SERVLET_NAME
Default Servlet name used by WebLogic

See Also:
Constant Field Values

WEBSPHERE_DEFAULT_SERVLET_NAME

private static final java.lang.String WEBSPHERE_DEFAULT_SERVLET_NAME
Default Servlet name used by WebSphere

See Also:
Constant Field Values

defaultServletName

private java.lang.String defaultServletName

servletContext

private ServletContext servletContext
Constructor Detail

DefaultServletHttpRequestHandler

public DefaultServletHttpRequestHandler()
Method Detail

setDefaultServletName

public void setDefaultServletName(java.lang.String defaultServletName)
Set the name of the default Servlet to be forwarded to for static resource requests.


setServletContext

public void setServletContext(ServletContext servletContext)
If the defaultServletName property has not been explicitly set, attempts to locate the default Servlet using the known common container-specific names.

Specified by:
setServletContext in interface ServletContextAware
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,
                          java.io.IOException
Description copied from interface: HttpRequestHandler
Process the given request, generating a response.

Specified by:
handleRequest in interface HttpRequestHandler
Parameters:
request - current HTTP request
response - current HTTP response
Throws:
ServletException - in case of general errors
java.io.IOException - in case of I/O errors