Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame^] | 1 | <html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Apache Tomcat 6.0 (6.0.39) - Default Servlet Reference</title><meta name="author" content="Tim Funk"><style type="text/css" media="print">
|
| 2 | .noPrint {display: none;}
|
| 3 | td#mainBody {width: 100%;}
|
| 4 | </style></head><body bgcolor="#ffffff" text="#000000" link="#525D76" alink="#525D76" vlink="#525D76"><table border="0" width="100%" cellspacing="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="http://tomcat.apache.org/"><img src="./images/tomcat.gif" align="right" alt="
|
| 5 | The Apache Tomcat Servlet/JSP Container
|
| 6 | " border="0"></a></td><td><h1><font face="arial,helvetica,sanserif">Apache Tomcat 6.0</font></h1><font face="arial,helvetica,sanserif">Version 6.0.39, Jan 27 2014</font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img src="./images/asf-logo.gif" align="right" alt="Apache Logo" border="0"></a></td></tr></table><table border="0" width="100%" cellspacing="4"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr noshade="noshade" size="1"></td></tr><tr><!--LEFT SIDE NAVIGATION--><td width="20%" valign="top" nowrap="nowrap" class="noPrint"><p><strong>Links</strong></p><ul><li><a href="index.html">Docs Home</a></li><li><a href="http://wiki.apache.org/tomcat/FAQ">FAQ</a></li></ul><p><strong>User Guide</strong></p><ul><li><a href="introduction.html">1) Introduction</a></li><li><a href="setup.html">2) Setup</a></li><li><a href="appdev/index.html">3) First webapp</a></li><li><a href="deployer-howto.html">4) Deployer</a></li><li><a href="manager-howto.html">5) Manager</a></li><li><a href="realm-howto.html">6) Realms and AAA</a></li><li><a href="security-manager-howto.html">7) Security Manager</a></li><li><a href="jndi-resources-howto.html">8) JNDI Resources</a></li><li><a href="jndi-datasource-examples-howto.html">9) JDBC DataSources</a></li><li><a href="class-loader-howto.html">10) Classloading</a></li><li><a href="jasper-howto.html">11) JSPs</a></li><li><a href="ssl-howto.html">12) SSL</a></li><li><a href="ssi-howto.html">13) SSI</a></li><li><a href="cgi-howto.html">14) CGI</a></li><li><a href="proxy-howto.html">15) Proxy Support</a></li><li><a href="mbeans-descriptor-howto.html">16) MBean Descriptor</a></li><li><a href="default-servlet.html">17) Default Servlet</a></li><li><a href="cluster-howto.html">18) Clustering</a></li><li><a href="balancer-howto.html">19) Load Balancer</a></li><li><a href="connectors.html">20) Connectors</a></li><li><a href="monitoring.html">21) Monitoring and Management</a></li><li><a href="logging.html">22) Logging</a></li><li><a href="apr.html">23) APR/Native</a></li><li><a href="virtual-hosting-howto.html">24) Virtual Hosting</a></li><li><a href="aio.html">25) Advanced IO</a></li><li><a href="extras.html">26) Additional Components</a></li><li><a href="maven-jars.html">27) Mavenized</a></li></ul><p><strong>Reference</strong></p><ul><li><a href="RELEASE-NOTES.txt">Release Notes</a></li><li><a href="config/index.html">Configuration</a></li><li><a href="api/index.html">Javadocs</a></li><li><a href="http://tomcat.apache.org/connectors-doc/">JK 1.2 Documentation</a></li></ul><p><strong>Apache Tomcat Development</strong></p><ul><li><a href="building.html">Building</a></li><li><a href="changelog.html">Changelog</a></li><li><a href="http://wiki.apache.org/tomcat/TomcatVersions">Status</a></li><li><a href="developers.html">Developers</a></li><li><a href="architecture/index.html">Architecture</a></li><li><a href="funcspecs/index.html">Functional Specs.</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left" id="mainBody"><h1>Apache Tomcat 6.0</h1><h2>Default Servlet Reference</h2><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Table of Contents"><!--()--></a><a name="Table_of_Contents"><strong>Table of Contents</strong></a></font></td></tr><tr><td><blockquote>
|
| 7 | <ul><li><a href="#what">What is the DefaultServlet</a></li><li><a href="#where">Where is it declared?</a></li><li><a href="#change">What can I change?</a></li><li><a href="#dir">How do I customize directory listings?</a></li><li><a href="#secure">How do I secure directory listings?</a></li></ul>
|
| 8 | </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="what"><strong>What is the DefaultServlet</strong></a></font></td></tr><tr><td><blockquote>
|
| 9 | The default servlet is the servlet which serves static resources as well
|
| 10 | as serves the directory listings (if directory listings are enabled).
|
| 11 |
|
| 12 | </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="where"><strong>Where is it declared?</strong></a></font></td></tr><tr><td><blockquote>
|
| 13 | It is declared globally in <i>$CATALINA_BASE/conf/web.xml</i>.
|
| 14 | By default here is it's declaration:
|
| 15 | <div align="left"><table cellspacing="4" cellpadding="0" border="0"><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#ffffff" height="1"><pre>
|
| 16 | <servlet>
|
| 17 | <servlet-name>default</servlet-name>
|
| 18 | <servlet-class>
|
| 19 | org.apache.catalina.servlets.DefaultServlet
|
| 20 | </servlet-class>
|
| 21 | <init-param>
|
| 22 | <param-name>debug</param-name>
|
| 23 | <param-value>0</param-value>
|
| 24 | </init-param>
|
| 25 | <init-param>
|
| 26 | <param-name>listings</param-name>
|
| 27 | <param-value>true</param-value>
|
| 28 | </init-param>
|
| 29 | <load-on-startup>1</load-on-startup>
|
| 30 | </servlet>
|
| 31 |
|
| 32 | ...
|
| 33 |
|
| 34 | <servlet-mapping>
|
| 35 | <servlet-name>default</servlet-name>
|
| 36 | <url-pattern>/</url-pattern>
|
| 37 | </servlet-mapping>
|
| 38 |
|
| 39 | </pre></td><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr></table></div>
|
| 40 |
|
| 41 | So by default, the default servlet is loaded at webapp startup and
|
| 42 | directory listings are enabled and debugging is turned off.
|
| 43 | </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="change"><strong>What can I change?</strong></a></font></td></tr><tr><td><blockquote>
|
| 44 | The DefaultServlet allows the following initParamters:
|
| 45 |
|
| 46 | <table border="1">
|
| 47 | <tr>
|
| 48 | <th valign="top">debug</th>
|
| 49 | <td valign="top">
|
| 50 | Debugging level. It is not very useful unless you are a tomcat
|
| 51 | developer. As
|
| 52 | of this writing, useful values are 0, 1, 11, 1000.
|
| 53 | </td>
|
| 54 | </tr>
|
| 55 | <tr>
|
| 56 | <th valign="top">listings</th>
|
| 57 | <td valign="top">
|
| 58 | If no welcome file is present, can a directory listing be
|
| 59 | shown?
|
| 60 | value may be <b>true</b> or <b>false</b>
|
| 61 | <br>
|
| 62 | Welcome files are part of the servlet api.
|
| 63 | <br>
|
| 64 | <b>WARNING:</b> Listings of directories containing many entries are
|
| 65 | expensive. Multiple requests for large directory listings can consume
|
| 66 | significant proportions of server resources.
|
| 67 | </td>
|
| 68 | </tr>
|
| 69 | <tr>
|
| 70 | <th valign="top">readmeFile</th>
|
| 71 | <td valign="top">
|
| 72 | If a directory listing is presented, a readme file may also
|
| 73 | be presented with the listing. This file is inserted as is
|
| 74 | so it may contain HTML. default value is null
|
| 75 | </td>
|
| 76 | </tr>
|
| 77 | <tr>
|
| 78 | <th valign="top">globalXsltFile</th>
|
| 79 | <td valign="top">
|
| 80 | If you wish to customize your directory listing, you
|
| 81 | can use an XSL transformation. This value is an absolute
|
| 82 | file name which be used for all directory listings.
|
| 83 | This can be overridden per context and/or per directory. See
|
| 84 | <strong>contextXsltFile</strong> and <strong>localXsltFile</strong>
|
| 85 | below. The format of the xml is shown below.
|
| 86 | </td>
|
| 87 | </tr>
|
| 88 | <tr>
|
| 89 | <th valign="top">contextXsltFile</th>
|
| 90 | <td valign="top">
|
| 91 | You may also customize your directory listing by context by
|
| 92 | configuring <code>contextXsltFile</code>. This should be a context
|
| 93 | relative path (e.g.: <code>/path/to/context.xslt</code>). This
|
| 94 | overrides <code>globalXsltFile</code>. If this value is present but a
|
| 95 | file does not exist, then <code>globalXsltFile</code> will be used. If
|
| 96 | <code>globalXsltFile</code> does not exist, then the default
|
| 97 | directory listing will be shown.
|
| 98 | </td>
|
| 99 | </tr>
|
| 100 | <tr>
|
| 101 | <th valign="top">localXsltFile</th>
|
| 102 | <td valign="top">
|
| 103 | You may also customize your directory listing by directory by
|
| 104 | configuring <code>localXsltFile</code>. This should be a relative
|
| 105 | file name in the directory where the listing will take place.
|
| 106 | This overrides <code>globalXsltFile</code> and
|
| 107 | <code>contextXsltFile</code>. If this value is present but a file
|
| 108 | does not exist, then <code>contextXsltFile</code> will be used. If
|
| 109 | <code>contextXsltFile</code> does not exist, then
|
| 110 | <code>globalXsltFile</code> will be used. If
|
| 111 | <code>globalXsltFile</code> does not exist, then the default
|
| 112 | directory listing will be shown.
|
| 113 | </td>
|
| 114 | </tr>
|
| 115 | <tr>
|
| 116 | <th valign="top">input</th>
|
| 117 | <td valign="top">
|
| 118 | Input buffer size (in bytes) when reading
|
| 119 | resources to be served. [2048]
|
| 120 | </td>
|
| 121 | </tr>
|
| 122 | <tr>
|
| 123 | <th valign="top">output</th>
|
| 124 | <td valign="top">
|
| 125 | Output buffer size (in bytes) when writing
|
| 126 | resources to be served. [2048]
|
| 127 | </td>
|
| 128 | </tr>
|
| 129 | <tr>
|
| 130 | <th valign="top">readonly</th>
|
| 131 | <td valign="top">
|
| 132 | Is this context "read only", so HTTP commands like PUT and
|
| 133 | DELETE are rejected? [true]
|
| 134 | </td>
|
| 135 | </tr>
|
| 136 | <tr>
|
| 137 | <th valign="top">fileEncoding</th>
|
| 138 | <td valign="top">
|
| 139 | File encoding to be used when reading static resources.
|
| 140 | [platform default]
|
| 141 | </td>
|
| 142 | </tr>
|
| 143 | <tr>
|
| 144 | <th valign="top">sendfileSize</th>
|
| 145 | <td valign="top">
|
| 146 | If the connector used supports sendfile, this represents the minimal
|
| 147 | file size in KB for which sendfile will be used. Use a negative value
|
| 148 | to always disable sendfile. [48]
|
| 149 | </td>
|
| 150 | </tr>
|
| 151 | <tr>
|
| 152 | <th valign="top">useAcceptRanges</th>
|
| 153 | <td valign="top">
|
| 154 | If true, the Accept-Ranges header will be set when appropriate for the
|
| 155 | response. [true]
|
| 156 | </td>
|
| 157 | </tr>
|
| 158 |
|
| 159 | </table>
|
| 160 | </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="dir"><strong>How do I customize directory listings?</strong></a></font></td></tr><tr><td><blockquote>
|
| 161 | <p>You can override DefaultServlet with you own implementation and use that
|
| 162 | in your web.xml declaration. If you
|
| 163 | can understand what was just said, we will assume you can read the code
|
| 164 | to DefaultServlet servlet and make the appropriate adjustments. (If not,
|
| 165 | then that method isn't for you)
|
| 166 | </p>
|
| 167 | <p>
|
| 168 | You can use either <code>localXsltFile</code> or
|
| 169 | <code>globalXsltFile</code> and DefaultServlet will create
|
| 170 | an xml document and run it through an xsl transformation based
|
| 171 | on the values provided in <code>localXsltFile</code> and
|
| 172 | <code>globalXsltFile</code>. <code>localXsltFile</code> is first
|
| 173 | checked, followed by <code>globalXsltFile</code>, then default
|
| 174 | behaviors takes place.
|
| 175 | </p>
|
| 176 |
|
| 177 | <p>
|
| 178 | Format:
|
| 179 | <div align="left"><table cellspacing="4" cellpadding="0" border="0"><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#ffffff" height="1"><pre>
|
| 180 | <listing>
|
| 181 | <entries>
|
| 182 | <entry type='file|dir' urlPath='aPath' size='###' date='gmt date'>
|
| 183 | fileName1
|
| 184 | </entry>
|
| 185 | <entry type='file|dir' urlPath='aPath' size='###' date='gmt date'>
|
| 186 | fileName2
|
| 187 | </entry>
|
| 188 | ...
|
| 189 | </entries>
|
| 190 | <readme></readme>
|
| 191 | </listing>
|
| 192 | </pre></td><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr></table></div>
|
| 193 | <ul>
|
| 194 | <li>size will be missing if <code>type='dir'</code></li>
|
| 195 | <li>Readme is a CDATA entry</li>
|
| 196 | </ul>
|
| 197 | </p>
|
| 198 | The following is a sample xsl file which mimics the default tomcat behavior:
|
| 199 | <div align="left"><table cellspacing="4" cellpadding="0" border="0"><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#ffffff" height="1"><pre>
|
| 200 | <?xml version="1.0"?>
|
| 201 |
|
| 202 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
| 203 | version="1.0">
|
| 204 |
|
| 205 | <xsl:output method="xhtml" encoding="iso-8859-1" indent="no"/>
|
| 206 |
|
| 207 | <xsl:template match="listing">
|
| 208 | <html>
|
| 209 | <head>
|
| 210 | <title>
|
| 211 | Sample Directory Listing For
|
| 212 | <xsl:value-of select="@directory"/>
|
| 213 | </title>
|
| 214 | <style>
|
| 215 | h1{color : white;background-color : #0086b2;}
|
| 216 | h3{color : white;background-color : #0086b2;}
|
| 217 | body{font-family : sans-serif,Arial,Tahoma;
|
| 218 | color : black;background-color : white;}
|
| 219 | b{color : white;background-color : #0086b2;}
|
| 220 | a{color : black;} HR{color : #0086b2;}
|
| 221 | </style>
|
| 222 | </head>
|
| 223 | <body>
|
| 224 | <h1>Sample Directory Listing For
|
| 225 | <xsl:value-of select="@directory"/>
|
| 226 | </h1>
|
| 227 | <hr size="1" />
|
| 228 | <table cellspacing="0"
|
| 229 | width="100%"
|
| 230 | cellpadding="5"
|
| 231 | align="center">
|
| 232 | <tr>
|
| 233 | <th align="left">Filename</th>
|
| 234 | <th align="center">Size</th>
|
| 235 | <th align="right">Last Modified</th>
|
| 236 | </tr>
|
| 237 | <xsl:apply-templates select="entries"/>
|
| 238 | </table>
|
| 239 | <xsl:apply-templates select="readme"/>
|
| 240 | <hr size="1" />
|
| 241 | <h3>Apache Tomcat/6.0</h3>
|
| 242 | </body>
|
| 243 | </html>
|
| 244 | </xsl:template>
|
| 245 |
|
| 246 |
|
| 247 | <xsl:template match="entries">
|
| 248 | <xsl:apply-templates select="entry"/>
|
| 249 | </xsl:template>
|
| 250 |
|
| 251 | <xsl:template match="readme">
|
| 252 | <hr size="1" />
|
| 253 | <pre><xsl:apply-templates/></pre>
|
| 254 | </xsl:template>
|
| 255 |
|
| 256 | <xsl:template match="entry">
|
| 257 | <tr>
|
| 258 | <td align="left">
|
| 259 | <xsl:variable name="urlPath" select="@urlPath"/>
|
| 260 | <a href="{$urlPath}">
|
| 261 | <tt><xsl:apply-templates/></tt>
|
| 262 | </a>
|
| 263 | </td>
|
| 264 | <td align="right">
|
| 265 | <tt><xsl:value-of select="@size"/></tt>
|
| 266 | </td>
|
| 267 | <td align="right">
|
| 268 | <tt><xsl:value-of select="@date"/></tt>
|
| 269 | </td>
|
| 270 | </tr>
|
| 271 | </xsl:template>
|
| 272 |
|
| 273 | </xsl:stylesheet>
|
| 274 | </pre></td><td bgcolor="#023264" width="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr><tr><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td><td bgcolor="#023264" width="1" height="1"><img src="./images/void.gif" alt="" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr></table></div>
|
| 275 |
|
| 276 | </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="secure"><strong>How do I secure directory listings?</strong></a></font></td></tr><tr><td><blockquote>
|
| 277 | Use web.xml in each individual webapp. See the security section of the
|
| 278 | Servlet specification.
|
| 279 |
|
| 280 | </blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr noshade="noshade" size="1"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font color="#525D76" size="-1"><em>
|
| 281 | Copyright © 1999-2014, Apache Software Foundation
|
| 282 | </em></font></div></td></tr></table></body></html> |