Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.web.context
Class ContextLoaderServlet

    java.lang.Object
      javax.servlet.GenericServlet
          javax.servlet.http.HttpServlet
              org.springframework.web.context.ContextLoaderServlet

All Implemented Interfaces:
  Serializable, Servlet, ServletConfig

    public class ContextLoaderServlet

extends HttpServlet

Bootstrap servlet to start up Spring's root `WebApplicationContext`. Simply delegates to `ContextLoader`.

This servlet should have a lower `load-on-startup` value in `web.xml` than any servlets that access the root web application context.

Note that this class has been deprecated for containers implementing Servlet API 2.4 or higher, in favor of `ContextLoaderListener`.
According to Servlet 2.4, listeners must be initialized before load-on-startup servlets. Many Servlet 2.3 containers already enforce this behavior. If you use such a container, this servlet can be replaced with ContextLoaderListener.

Servlet 2.3 containers known to work with bootstrap listeners are:

- Apache Tomcat 4.x+
- Jetty 4.x+
- Resin 2.1.8+
- Orion 2.0.2+
- BEA WebLogic 8.1 SP3

For working with any of them, ContextLoaderListener is recommended.

Servlet 2.3 containers known not to work with bootstrap listeners are:

- BEA WebLogic up to 8.1 SP2
- IBM WebSphere 5.x
- Oracle OC4J 9.0.3

If you happen to work with such a server, this servlet has to be used.

So unfortunately, the only context initialization option that is compatible with all Servlet 2.3 containers is this servlet.

Note that a startup failure of this servlet will not stop the rest of the web application from starting, in contrast to a listener failure. This can lead to peculiar side effects if other servlets get started that depend on initialization of the root web application context.

Author:
  Juergen Hoeller, Darren Davison
See Also:
  `ContextLoaderListener`, `Log4jConfigServlet`, Serialized Form

Constructor Summary
`ContextLoaderServlet()`

Method Summary
`protected ContextLoader` | `createContextLoader()` Create the ContextLoader to use.
`void` | `destroy()` Close the root web application context.
`ContextLoader` | `getContextLoader()` Return the ContextLoader used by this servlet.
`String` | `getServletInfo()`
`void` | `init()` Initialize the root web application context.
`void` | `service(HttpServletRequest request, HttpServletResponse response)` This should never even be called since no mapping to this servlet should ever be created in web.xml.

Methods inherited from class javax.servlet.http.HttpServlet
`doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service`

Methods inherited from class javax.servlet.GenericServlet
`getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ContextLoaderServlet

    public ContextLoaderServlet()

Method Detail

### init

    public void init()
              throws ServletException

  Initialize the root web application context.

  Overrides:
    `init` in class `GenericServlet`
  Throws:
    `ServletException`

### createContextLoader

    protected ContextLoader createContextLoader()

  Create the ContextLoader to use. Can be overridden in subclasses.

  Returns:
    the new ContextLoader

### getContextLoader

    public ContextLoader getContextLoader()

  Return the ContextLoader used by this servlet.

  Returns:
    the current ContextLoader

### destroy

    public void destroy()

  Close the root web application context.

  Specified by:
    `destroy` in interface `Servlet`
  Overrides:
    `destroy` in class `GenericServlet`

### service

    public void service(HttpServletRequest request,
                        HttpServletResponse response)
                 throws IOException

  This should never even be called since no mapping to this servlet should ever be created in web.xml. That's why a correctly invoked Servlet 2.3 listener is much more appropriate for initialization work ;-)

  Overrides:
    `service` in class `HttpServlet`
  Throws:
    `IOException`

### getServletInfo

    public String getServletInfo()

  Specified by:
    `getServletInfo` in interface `Servlet`
  Overrides:
    `getServletInfo` in class `GenericServlet`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2007 The Spring Framework.