web.xml reference - novalexei/mod_servlet GitHub Wiki

###web.xml Reference for mod_servlet

####Introduction

The web.xml Deployment Descriptor file describes how to deploy a web application in mod_servlet container

This file is required for every application you deploy on mod_servlet.

The location of the file is always the same: application-root/WEB-INF/web.xml

At minimum, the file needs to contain an XML descriptor and an opening and closing <web-app> tag.

####Example:

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
    <!-- =============================================================== -->
    <!-- servlets -->
    <servlet>
        <servlet-name>TestServlet</servlet-name>
        <servlet-factory>libtest_servlet.so:testServlet</servlet-factory>
        <!-- This servlet has 2 parameters -->
        <init-param>
            <param-name>test.param.1</param-name>
            <param-value>test.value.1</param-value>
        </init-param>
        <init-param>
            <param-name>test.param.2</param-name>
            <param-value>test.value.2</param-value>
        </init-param>
    </servlet>
    <!-- TestServlet will map it to all URL's starting from '/tst/' -->
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/tst/*</url-pattern>
    </servlet-mapping>
    <!-- Configure initialization servlet -->
    <servlet>
        <!-- This servlet doesn't have corresponding 'servlet-mapping' -->
        <!-- It just initializes the application -->
        <servlet-name>InitServlet</servlet-name>
        <servlet-factory>libtest_servlet.so:initServlet</servlet-factory>
        <load-on-startup>5</load-on-startup>
    </servlet>
    <!-- =============================================================== -->
    <!-- filters -->
    <filter>
        <filter-name>TestURLFilter</filter-name>
        <filter-factory>libtest_servlet.so:testURLFilter</filter-factory>
        <!-- This filter has 1 parameter -->
        <init-param>
            <param-name>test.param.filter</param-name>
            <param-value>test.value.filter</param-value>
        </init-param>
    </filter>
    <!-- This filter has URL mapping and will be invoked on all URL's -->
    <filter-mapping>
        <filter-name>TestURLFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter>
        <filter-name>TestNameFilter</filter-name>
        <filter-factory>libtest_servlet.so:testNameFilter</filter-factory>
    </filter>
    <!-- This filter has servlet name mapping -->
    <!-- It will be invoked when TestServlet is called -->
    <filter-mapping>
        <filter-name>TestNameFilter</filter-name>
        <servlet-name>TestServlet</servlet-name>
    </filter-mapping>
    <!-- =============================================================== -->
    <!-- Custom error pages -->
    <error-page>
        <error-code>404</error-code>
        <location>/not_found.html</location>
    </error-page>
    <!-- =============================================================== -->
    <!-- Custom mime-type mappings -->
    <mime-mapping>
        <extension>xls</extension>
        <mime-type>application/vnd.ms-excel</mime-type>
    </mime-mapping>
    <!-- =============================================================== -->
    <!-- Session timeout -->
    <session-config>
        <session-timeout>120</session-timeout>
    </session-config>
</web-app>
⚠️ **GitHub.com Fallback** ⚠️