### Servlet

code

docs

tests

This library provide the necessary boilerplate code to bootstrap a Zest™ Application in a Servlet container plus some facilities. It aims at a very simple need and is provided as an example integration.

If instead you want to run a servlet container inside a Zest™ Application, see HTTP Library.

Table 45. Artifact

Group ID | Artifact ID | Version
--- | --- | ---
org.qi4j.library | org.qi4j.library.servlet | 2.1

#### Application Bootstrap

Extends `AbstractQi4jServletBootstrap` to easily bind a Zest™ `Application` activation/passivation to your webapp lifecycle.

Use `Qi4jServletSupport#application(javax.servlet.ServletContext)` to get a handle on the `Application` from the `ServletContext`.

Here is an example ServletContextListener:

    public static class FooServletContextListener
            extends AbstractQi4jServletBootstrap
    {

        public ApplicationAssembly assemble( ApplicationAssemblyFactory applicationFactory )
                throws AssemblyException
        {
            ApplicationAssembly appass = applicationFactory.newApplicationAssembly();
            [...snip...]

            return appass;
        }

    }

#### Facilities

`Qi4jServlet` and `Qi4jFilter` respectively provide base class for easy access to the `Application` from the `ServletContext`.

Here is a sample servlet that simply output the assembled Application name:

    public static class FooServlet
            extends Qi4jServlet
    {

        @Override
        protected void doGet( HttpServletRequest req, HttpServletResponse resp )
                throws ServletException, IOException
        {
            // Output the assembled Application's name as an example
            resp.getWriter().println( application().name() );
        }

    }

#### Logging

The SLF4J logger used by this library is named "org.qi4j.library.servlet".