Filters
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Quercus
Servlets and Filters
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

Servlets
Servlet Lib
run-at
Filters
Filter Lib
Tutorials
FAQ
run-at
Servlets and Filters
Filter Lib

  1. Index
  2. Filter Configuration

    Index
    filterDefines a filter alias for later mapping
    filter-classClass of the filter
    filter-mappingMaps url patterns to filters
    filter-nameAlias of the filter
    init-paramInitializes filter variables

    Filter configuration follows the Servlet 2.3 deployment descriptors. Creating and using a filter has three steps:

    1. Create a filter class which extends javax.servlet.Filter
    2. Use <filter> in the web.xml to configure the filter.
    3. Use <filter-mapping> to select URLs and servlets for the filter.

    Some other pages which discuss filters include:

    Filter Configuration

    filter

    Servlet 2.3

    Defines a filter alias for later mapping.

    TagMeaning
    filter-nameThe filter's name (alias)
    filter-classThe filter's class (defaults to servlet-name)
    init-paramInitialization parameters

    The following example defines a filter alias 'image'

    <web-app id='/'>
    
    <filter-mapping url-pattern='/images/*'
                     filter-name='image'/>
    
    <filter filter-name='image'
             filter-class='test.MyImage'>
      <init-param title='Hello, World'/>
    </filter>
    
    </web-app>
    

    filter-name

    Servlet 2.3

    Alias of the filter.

    filter-class

    Servlet 2.3

    Class of the filter. The CLASSPATH for filters includes the WEB-INF/classes directory and all jars in the WEB-INF/lib directory.

    init-param

    Servlet 2.3

    Initializes filter variables. filter-param defines initial values for getFilterConfig().getInitParameter("foo").

    The full Servlet 2.3 syntax for init-param is supported and allows a simple shortcut

    <web-app id='/'>
    
    <filter filter-name='test.HelloWorld'>
      <init-param foo='bar'/>
    
      <init-param>
        <param-name>baz</param-name>
        <param-value>value</param-value>
      </init-param>
    </filter>
    
    </web-app>
    

    filter-mapping

    Servlet 2.3

    Maps url patterns to filters. filter-mapping has two children, url-pattern and filter-name. url-pattern selects the urls which should execute the filter.

    filter-name can either specify a servlet class directly or it can specify a servlet alias defined by filter.

    ConfigurationDescription
    url-patternA pattern matching the url: /foo/*, /foo, or *.foo
    url-regexpA regular expression matching the url
    servlet-nameA servlet name to match.
    filter-nameThe filter name
    filter-classThe filter class
    init-paramInitialization parameters

    <caucho.com>
    <web-app id='/'>
    
    <servlet servlet-name='hello'
             servlet-class='test.HelloWorld'/>
    
    <servlet-mapping url-pattern='/hello'
                     servlet-name='hello'/>
    
    <filter filter-name='test-filter'
            filter-class='test.MyFilter'/>
    
    <filter-mapping url-pattern='/hello/*'
                     filter-name='test-filter'/>
    
    <filter-mapping servlet-name='hello'
                     filter-name='test.SecondFilter'/>
    
    </web-app>
    


    run-at
    Servlets and Filters
    Filter Lib
    Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
    Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.