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

## org.apache.struts2.dispatcher
Class FilterDispatcher

    java.lang.Object
      org.apache.struts2.dispatcher.FilterDispatcher

All Implemented Interfaces:
  javax.servlet.Filter, StrutsStatics

Direct Known Subclasses:
  FilterDispatcherCompatWeblogic61

Deprecated. Since Struts 2.1.3, use `StrutsPrepareAndExecuteFilter` instead or `StrutsPrepareFilter` and `StrutsExecuteFilter` if needing using the `ActionContextCleanUp` filter in addition to this one

    public class FilterDispatcher

extends Object
implements StrutsStatics, javax.servlet.Filter

Master filter for Struts that handles four distinct responsibilities:

- Executing actions

- Cleaning up the `ActionContext` (see note)

- Serving static content

- Kicking off XWork's interceptor chain for the request lifecycle

IMPORTANT: this filter must be mapped to all requests. Unless you know exactly what you are doing, always map to this URL pattern: /*

Executing actions

This filter executes actions by consulting the `ActionMapper` and determining if the requested URL should invoke an action. If the mapper indicates it should, the rest of the filter chain is stopped and the action is invoked. This is important, as it means that filters like the SiteMesh filter must be placed before this filter or they will not be able to decorate the output of actions.

Cleaning up the `ActionContext`

This filter will also automatically clean up the `ActionContext` for you, ensuring that no memory leaks take place. However, this can sometimes cause problems integrating with other products like SiteMesh. See `ActionContextCleanUp` for more information on how to deal with this.

Serving static content

This filter also serves common static content needed when using various parts of Struts, such as JavaScript files, CSS files, etc. It works by looking for requests to /struts/*, and then mapping the value after "/struts/" to common packages in Struts and, optionally, in your class path. By default, the following packages are automatically searched:

- org.apache.struts2.static

- template

This means that you can simply request /struts/xhtml/styles.css and the XHTML UI theme's default stylesheet will be returned. Likewise, many of the AJAX UI components require various JavaScript files, which are found in the org.apache.struts2.static package. If you wish to add additional packages to be searched, you can add a comma separated (space, tab and new line will do as well) list in the filter init parameter named "packages". Be careful, however, to expose any packages that may have sensitive information, such as properties file with database access credentials.

This filter supports the following init-params:

- config - a comma-delimited list of XML configuration files to load.

- actionPackages - a comma-delimited list of Java packages to scan for Actions.

- configProviders - a comma-delimited list of Java classes that implement the `ConfigurationProvider` interface that should be used for building the `Configuration`.

- loggerFactory - The class name of the `LoggerFactory` implementation.

- * - any other parameters are treated as framework constants.

To use a custom `Dispatcher`, the `createDispatcher()` method could be overriden by the subclass.

Version:
  $Date$ $Id$
See Also:
  `ActionMapper`, `ActionContextCleanUp`, `StrutsPrepareAndExecuteFilter`, `StrutsPrepareFilter`, `StrutsExecuteFilter`

Field Summary
`protected Dispatcher` | `dispatcher` Deprecated. Expose Dispatcher instance to subclass.
`protected StaticContentLoader` | `staticResourceLoader` Deprecated. Loads static resources, set by injection.

Fields inherited from interface org.apache.struts2.StrutsStatics
`HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT`

Constructor Summary
`FilterDispatcher()` Deprecated.

Method Summary
`protected Dispatcher` | `createDispatcher(javax.servlet.FilterConfig filterConfig)` Deprecated. Create a default `Dispatcher` that subclasses can override with a custom Dispatcher, if needed.
`protected Dispatcher` | `createDispatcher(javax.servlet.ServletContext ctx, Map<String,String> params)` Deprecated. Create a default `Dispatcher` that subclasses can override with a custom Dispatcher, if needed.
`void` | `destroy()` Deprecated. Calls dispatcher.cleanup, which in turn releases local threads and destroys any DispatchListeners.
`void` | `doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)` Deprecated. Process an action or handle a request a static resource.
`static Boolean` | `getDevModeOverride()` Deprecated.
`protected javax.servlet.FilterConfig` | `getFilterConfig()` Deprecated. Expose the FilterConfig instance.
`protected javax.servlet.ServletContext` | `getServletContext()` Deprecated. Provide a workaround for some versions of WebLogic.
`void` | `init(javax.servlet.FilterConfig filterConfig)` Deprecated. Initializes the filter by creating a default dispatcher and setting the default packages for static resources.
`static void` | `overrideDevMode(boolean devMode)` Deprecated. Set an override of the static devMode value.
`protected javax.servlet.http.HttpServletRequest` | `prepareDispatcherAndWrapRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Deprecated. Wrap and return the given request, if needed, so as to to transparently handle multipart data as a wrapped class around the given request.
`void` | `setActionMapper(ActionMapper mapper)` Deprecated. Modify ActionMapper instance.
`void` | `setStaticResourceLoader(StaticContentLoader staticResourceLoader)` Deprecated. Modify state of StrutsConstants.STRUTS_STATIC_CONTENT_LOADER setting.

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

Field Detail

### dispatcher

    protected Dispatcher dispatcher

  Deprecated.
  Expose Dispatcher instance to subclass.

### staticResourceLoader

    protected StaticContentLoader staticResourceLoader

  Deprecated.
  Loads static resources, set by injection.

Constructor Detail

### FilterDispatcher

    public FilterDispatcher()

  Deprecated.

Method Detail

### init

    public void init(javax.servlet.FilterConfig filterConfig)
              throws javax.servlet.ServletException

  Deprecated.
  Initializes the filter by creating a default dispatcher and setting the default packages for static resources.

  Specified by:
    `init` in interface `javax.servlet.Filter`
  Parameters:
    `filterConfig` - The filter configuration
  Throws:
    `javax.servlet.ServletException`

### destroy

    public void destroy()

  Deprecated.
  Calls dispatcher.cleanup, which in turn releases local threads and destroys any DispatchListeners.

  Specified by:
    `destroy` in interface `javax.servlet.Filter`
  See Also:
    `Filter.destroy()`

### overrideDevMode

    public static void overrideDevMode(boolean devMode)

  Deprecated.
  Set an override of the static devMode value. Do not set this via a request parameter or any other unprotected method. Using a signed cookie is one safe way to turn it on per request.

  Parameters:
    `devMode` - the override value

### getDevModeOverride

    public static Boolean getDevModeOverride()

  Deprecated.
  Returns:
    Boolean override value, or null if no override

### createDispatcher

    protected Dispatcher createDispatcher(javax.servlet.FilterConfig filterConfig)

  Deprecated.
  Create a default `Dispatcher` that subclasses can override with a custom Dispatcher, if needed.

  Parameters:
    `filterConfig` - Our FilterConfig
  Returns:
    Initialized Dispatcher

### createDispatcher

    protected Dispatcher createDispatcher(javax.servlet.ServletContext ctx,
                                          Map<String,String> params)

  Deprecated.
  Create a default `Dispatcher` that subclasses can override with a custom Dispatcher, if needed. Called by createDispatcher(FilterConfig).

  Parameters:
    `ctx` - ServletContext
    `params` - parameters from FilterConfig
  Returns:
    Initialized Dispatcher

### setStaticResourceLoader

    public void setStaticResourceLoader(StaticContentLoader staticResourceLoader)

  Deprecated.
  Modify state of StrutsConstants.STRUTS_STATIC_CONTENT_LOADER setting.

  Parameters:
    `staticResourceLoader` - val New setting

### setActionMapper

    public void setActionMapper(ActionMapper mapper)

  Deprecated.
  Modify ActionMapper instance.

  Parameters:
    `mapper` - New instance

### getServletContext

    protected javax.servlet.ServletContext getServletContext()

  Deprecated.
  Provide a workaround for some versions of WebLogic.

  Servlet 2.3 specifies that the servlet context can be retrieved from the session. Unfortunately, some versions of WebLogic can only retrieve the servlet context from the filter config. Hence, this method enables subclasses to retrieve the servlet context from other sources.

  Returns:
    the servlet context.

### getFilterConfig

    protected javax.servlet.FilterConfig getFilterConfig()

  Deprecated.
  Expose the FilterConfig instance.

  Returns:
    Our FilterConfit instance

### prepareDispatcherAndWrapRequest

    protected javax.servlet.http.HttpServletRequest prepareDispatcherAndWrapRequest(javax.servlet.http.HttpServletRequest request,
                                                                                    javax.servlet.http.HttpServletResponse response)
                                                                             throws javax.servlet.ServletException

  Deprecated.
  Wrap and return the given request, if needed, so as to to transparently handle multipart data as a wrapped class around the given request.

  Parameters:
    `request` - Our ServletRequest object
    `response` - Our ServerResponse object
  Returns:
    Wrapped HttpServletRequest object
  Throws:
    `javax.servlet.ServletException` - on any error

### doFilter

    public void doFilter(javax.servlet.ServletRequest req,
                         javax.servlet.ServletResponse res,
                         javax.servlet.FilterChain chain)
                  throws IOException,
                         javax.servlet.ServletException

  Deprecated.
  Process an action or handle a request a static resource.

  The filter tries to match the request to an action mapping. If mapping is found, the action processes is delegated to the dispatcher's serviceAction method. If action processing fails, doFilter will try to create an error page via the dispatcher.

  Otherwise, if the request is for a static resource, the resource is copied directly to the response, with the appropriate caching headers set.

  If the request does not match an action mapping, or a static resource page, then it passes through.

  Specified by:
    `doFilter` in interface `javax.servlet.Filter`
  Throws:
    `IOException`
    `javax.servlet.ServletException`
  See Also:
    `Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)`

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

Copyright © 2000–2018 Apache Software Foundation. All rights reserved.