Chapter 19 Understanding Default Servlet Reference
A default servlet serves static resources and directory listings. You can find its declaration code in $CATALINA_HOME/conf/web.xml:
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>
org.apache.catalina.servlets.DefaultServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
...
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
You may change the following initParameters:
- debug – This is on the debugging level.
- listings – This queries if it may be possible to display a list of directory.
- readmeFile – A readme file may be displayed along with the directory listing.
- globalXsltFile – Use an XSL transformation to customize directory listing.
- localXsltFile – Configure
localXsltFileto display the list of directory.
- input – This refers to the input buffer size when reading resources to be served.
- output – This refers to the output buffer size when writing resources to be served.
- readonly – This queries if HTTP commands should be rejected.
- fileEncoding – This is used when reading static resources.
- sendfileSize – This refers to the minimal size in KB for which sendfile is used.
Customizing Directory Listings
To customize directory listings, override DefaultServlet in web.xml declaration with your own implementation.
You may also use either localXsltFile or globalXsltFile and DefaultServer to create an XML document. Run the XML document through an XSL transformation based on the values provided in localXsltFile and globalXsltFile. localXsltFile is first checked, followed by globalXsltFile.
Format:
<listing>
<entries>
<entry type='file|dir' urlPath='aPath' size='###' date='gmt date'>
fileName1
</entry>
<entry type='file|dir' urlPath='aPath' size='###' date='gmt date'>
fileName2
</entry>
...
</entries>
<readme></readme>
</listing>
Notes:
- size will be missing if type= ‘dir’
- Readme is a CDATA entry


