Links
User Guide
Reference
Apache Tomcat Development
The default servlet is the servlet which serves static resources as well as serves the directory listings (if directory listings are enabled).
It is declared globally in $CATALINA_BASE/conf/web.xml. By default here is it's declaration:So by default, the default servlet is loaded at webapp startup and directory listings are enabled and debugging is turned off.<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>
What can I change? | ||||||||||||||||||||||||
The DefaultServlet allows the following initParamters: |
You can override DefaultServlet with you own implementation and use that in your web.xml declaration. If you can understand what was just said, we will assume you can read the code to DefaultServlet servlet and make the appropriate adjustments. (If not, then that method isn't for you)
You can use either
localXsltFile
orglobalXsltFile
and DefaultServlet will create an xml document and run it through an xsl transformation based on the values provided inlocalXsltFile
andglobalXsltFile
.localXsltFile
is first checked, followed byglobalXsltFile
, then default behaviors takes place.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>The following is a sample xsl file which mimics the default tomcat behavior:
- size will be missing if
type='dir'
- Readme is a CDATA entry
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xhtml" encoding="iso-8859-1" indent="no"/> <xsl:template match="listing"> <html> <head> <title> Sample Directory Listing For <xsl:value-of select="@directory"/> </title> <style> h1{color : white;background-color : #0086b2;} h3{color : white;background-color : #0086b2;} body{font-family : sans-serif,Arial,Tahoma; color : black;background-color : white;} b{color : white;background-color : #0086b2;} a{color : black;} HR{color : #0086b2;} </style> </head> <body> <h1>Sample Directory Listing For <xsl:value-of select="@directory"/> </h1> <hr size="1" /> <table cellspacing="0" width="100%" cellpadding="5" align="center"> <tr> <th align="left">Filename</th> <th align="center">Size</th> <th align="right">Last Modified</th> </tr> <xsl:apply-templates select="entries"/> </table> <xsl:apply-templates select="readme"/> <hr size="1" /> <h3>Apache Tomcat/6.0</h3> </body> </html> </xsl:template> <xsl:template match="entries"> <xsl:apply-templates select="entry"/> </xsl:template> <xsl:template match="readme"> <hr size="1" /> <pre><xsl:apply-templates/></pre> </xsl:template> <xsl:template match="entry"> <tr> <td align="left"> <xsl:variable name="urlPath" select="@urlPath"/> <a href="{$urlPath}"> <tt><xsl:apply-templates/></tt> </a> </td> <td align="right"> <tt><xsl:value-of select="@size"/></tt> </td> <td align="right"> <tt><xsl:value-of select="@date"/></tt> </td> </tr> </xsl:template> </xsl:stylesheet>
Use web.xml in each individual webapp. See the security section of the Servlet specification.