Philippe Marschall | 9 Jan 09:57 2010

Re: [jetty-user] adding a filter programmatically

On 02.01.2010 00:32, Greg Wilkins wrote:
> Chad,
> there is the javadoc:
> which is a little light on, but fairly self evident.
> I guess we should add a filter example to the embedded tutorial:
> if somebody wanted to contribute a simple example, then I'd add
> it to embedded examples and describe it in the tutorial.

There is one thing about adding filters that wasn't quite obvious to me.
If you application is just a filter (e.g. Wicket) then you still need to
add a "NullServlet".

I use something like this to add filters:

int options = ServletContextHandler.NO_SECURITY;
ServletContextHandler context = new ServletContextHandler(server, "/",

context.addFilter(MyFirstFilter.class, "/*", FilterMapping.REQUEST);

FilterHolder secondFilter = new FilterHolder(MySecondFilter.class);
secondFilter.setInitParameter("foo", "bar");
context.addFilter(secondFilter, "/*", FilterMapping.REQUEST);

context.addServlet(NullServlet.class, "/");


To unsubscribe from this list, please visit: