Question: I'd like the ability to modify/configure filters in a different way than web.xml. Here is a static configuration of 2 filters. I'd like the ability to have one filter statically configured and allow that filter to load additional filters. I just wanted to know if anyone knows of lib that already has this.

Using Servlet API 2.5

```xml
<web-app>
  ...
  <filter>
    <filter-name>MyFilter1</filter-name>
    <filter-class>com.me.MyFilter1</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>MyFilter1</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  ...
  <filter>
    <filter-name>MyFilter2</filter-name>
    <filter-class>com.me.MyFilter2</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>MyFilter2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  ...
</web-app>

```

I've seen this done in Guice with GuiceFilter where the Filters are configured at runtime.

Answer: 
It can be achieved in easy steps, even for pre-3.0 Servlet spec:

1. Add a filter containing a static & ordered collection of Classes (chain).
2. Map the filter to intercept every traffic.
3. Manipulate the order & existence of your helper classes (those will be called privately by your filter upon interception of traffic) in the chain.

Ref: Xstream uses same kind of pattern for Serializer, well not with Servlet/Filter though. :)
I personally like the [@WebFilter](https://tomcat.apache.org/tomcat-9.0-doc/servletapi/javax/servlet/annotation/WebFilter.html) annotation to register servlet filters.  

But another solution is to add the filter at runtime using the `ServletContext's` [addFilter](https://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html) function.

Implement `ServletContextListener`; something like:

```java
public class MyContextListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent ce) {
        ServletContext servletContext = ce.getServletContext();

        // you can even conditionally add this
        servletContext.addFilter("My filter 1", MyFilter1.class)
                .addMappingForUrlPatterns(allOf(DispatcherType.class), false, "/*");
    }
}

```

Register listener:

```xml
<listener>
    <listener-class>com.me.MyContextListener</listener-class>
</listener>   

```

And of course you need to implement a [Filter](https://docs.oracle.com/javaee/6/api/javax/servlet/Filter.html). But in your question you already refer to an example filter 'MyFilter1'.