Ninja is designed to not depend on a specific web container technology per se. You can run Ninja inside any servlet container - but also as Netty application.
In reality, however, Ninja tends to run 99% in servlet based containers. Tomcats, Jettys and so on. It is also true that many users want to have a clear migration path.
Your organization possibly already has a lot of Servlets you want to reuse. Or filters you wrote, or servlet based plugins you want to combine with Ninja.
The servlet bridge supports this use case and makes it really simple to combine servlet technology and Ninja to get the best of both worlds.
The best way to add servlets and filters to Ninja is to use Ninja's SevletModule
at /conf/ServletModule.java
.
public class ServletModule extends com.google.inject.servlet.ServletModule { @Override protected void configureServlets() { bind(LegacyServletFilter.class).asEagerSingleton(); bind(NinjaServletDispatcher.class).asEagerSingleton(); filter("/*").through(LegacyServletFilter.class); serve("/*").with(NinjaServletDispatcher.class); } }
We using an arbitrary Servlet filter (LegacyServletFilter) to filter stuff completely outside of Ninja. It is of course a better way to use Ninja's filters directly. But if you got a large legacy app it can make sense to combine both technologies for a smooth transition.
Please note: ServletFilter.java is optional. If the file is not present all requests will be handled by Ninja.
It is usually a better idea writing a module for Ninja and use Ninja's session mechanism to circumvent that problem.