blob: 4292307dd3a258a9be462c9dd58d454213e7c94c [file] [log] [blame]
Hongqing Liu71898292014-10-15 13:31:32 +08001<html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Apache Tomcat 6.0 (6.0.41) - Default Servlet Reference</title><meta name="author" content="Tim Funk"><style type="text/css" media="print">
Hongqing Liufd5ee812014-05-10 16:32:51 +08002 .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
Hongqing Liu71898292014-10-15 13:31:32 +08006 " 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.41, May 19 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>
Hongqing Liufd5ee812014-05-10 16:32:51 +08007<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>
9The default servlet is the servlet which serves static resources as well
10as 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>
13It is declared globally in <i>$CATALINA_BASE/conf/web.xml</i>.
14By 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 &lt;servlet&gt;
17 &lt;servlet-name&gt;default&lt;/servlet-name&gt;
18 &lt;servlet-class&gt;
19 org.apache.catalina.servlets.DefaultServlet
20 &lt;/servlet-class&gt;
21 &lt;init-param&gt;
22 &lt;param-name&gt;debug&lt;/param-name&gt;
23 &lt;param-value&gt;0&lt;/param-value&gt;
24 &lt;/init-param&gt;
25 &lt;init-param&gt;
26 &lt;param-name&gt;listings&lt;/param-name&gt;
27 &lt;param-value&gt;true&lt;/param-value&gt;
28 &lt;/init-param&gt;
29 &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
30 &lt;/servlet&gt;
31
32...
33
34 &lt;servlet-mapping&gt;
35 &lt;servlet-name&gt;default&lt;/servlet-name&gt;
36 &lt;url-pattern&gt;/&lt;/url-pattern&gt;
37 &lt;/servlet-mapping&gt;
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
41So by default, the default servlet is loaded at webapp startup and
42directory 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>
44The 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
Hongqing Liu71898292014-10-15 13:31:32 +080081 can use an XSL transformation. This value is a relative file name (to
82 either $CATALINA_BASE/conf/ or $CATALINA_HOME/conf/) which will be used
83 for all directory listings. This can be overridden per context and/or
84 per directory. See <strong>contextXsltFile</strong> and
85 <strong>localXsltFile</strong> below. The format of the xml is shown
86 below.
Hongqing Liufd5ee812014-05-10 16:32:51 +080087 </td>
88 </tr>
89 <tr>
90 <th valign="top">contextXsltFile</th>
91 <td valign="top">
92 You may also customize your directory listing by context by
Hongqing Liu71898292014-10-15 13:31:32 +080093 configuring <code>contextXsltFile</code>. This must be a context
94 relative path (e.g.: <code>/path/to/context.xslt</code>) to a file with
95 a <code>.xsl</code> or <code>.xslt</code> extension. This overrides
96 <code>globalXsltFile</code>. If this value is present but a file does
97 not exist, then <code>globalXsltFile</code> will be used. If
Hongqing Liufd5ee812014-05-10 16:32:51 +080098 <code>globalXsltFile</code> does not exist, then the default
99 directory listing will be shown.
100 </td>
101 </tr>
102 <tr>
103 <th valign="top">localXsltFile</th>
104 <td valign="top">
105 You may also customize your directory listing by directory by
Hongqing Liu71898292014-10-15 13:31:32 +0800106 configuring <code>localXsltFile</code>. This must be a file in the
107 directory where the listing will take place to with a
108 <code>.xsl</code> or <code>.xslt</code> extension. This overrides
109 <code>globalXsltFile</code> and <code>contextXsltFile</code>. If this
110 value is present but a file does not exist, then
111 <code>contextXsltFile</code> will be used. If
Hongqing Liufd5ee812014-05-10 16:32:51 +0800112 <code>contextXsltFile</code> does not exist, then
113 <code>globalXsltFile</code> will be used. If
114 <code>globalXsltFile</code> does not exist, then the default
115 directory listing will be shown.
116 </td>
117 </tr>
118 <tr>
119 <th valign="top">input</th>
120 <td valign="top">
121 Input buffer size (in bytes) when reading
122 resources to be served. [2048]
123 </td>
124 </tr>
125 <tr>
126 <th valign="top">output</th>
127 <td valign="top">
128 Output buffer size (in bytes) when writing
129 resources to be served. [2048]
130 </td>
131 </tr>
132 <tr>
133 <th valign="top">readonly</th>
134 <td valign="top">
135 Is this context "read only", so HTTP commands like PUT and
136 DELETE are rejected? [true]
137 </td>
138 </tr>
139 <tr>
140 <th valign="top">fileEncoding</th>
141 <td valign="top">
142 File encoding to be used when reading static resources.
143 [platform default]
144 </td>
145 </tr>
146 <tr>
147 <th valign="top">sendfileSize</th>
148 <td valign="top">
149 If the connector used supports sendfile, this represents the minimal
150 file size in KB for which sendfile will be used. Use a negative value
151 to always disable sendfile. [48]
152 </td>
153 </tr>
154 <tr>
155 <th valign="top">useAcceptRanges</th>
156 <td valign="top">
157 If true, the Accept-Ranges header will be set when appropriate for the
158 response. [true]
159 </td>
160 </tr>
161
162</table>
163</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>
164<p>You can override DefaultServlet with you own implementation and use that
165in your web.xml declaration. If you
166can understand what was just said, we will assume you can read the code
167to DefaultServlet servlet and make the appropriate adjustments. (If not,
168then that method isn't for you)
169</p>
170<p>
171You can use either <code>localXsltFile</code> or
172<code>globalXsltFile</code> and DefaultServlet will create
173an xml document and run it through an xsl transformation based
174on the values provided in <code>localXsltFile</code> and
175<code>globalXsltFile</code>. <code>localXsltFile</code> is first
176checked, followed by <code>globalXsltFile</code>, then default
177behaviors takes place.
178</p>
179
180<p>
181Format:
182<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>
183 &lt;listing&gt;
184 &lt;entries&gt;
185 &lt;entry type='file|dir' urlPath='aPath' size='###' date='gmt date'&gt;
186 fileName1
187 &lt;/entry&gt;
188 &lt;entry type='file|dir' urlPath='aPath' size='###' date='gmt date'&gt;
189 fileName2
190 &lt;/entry&gt;
191 ...
192 &lt;/entries&gt;
193 &lt;readme&gt;&lt;/readme&gt;
194 &lt;/listing&gt;
195</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>
196<ul>
197 <li>size will be missing if <code>type='dir'</code></li>
198 <li>Readme is a CDATA entry</li>
199</ul>
200</p>
201The following is a sample xsl file which mimics the default tomcat behavior:
202<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>
203&lt;?xml version="1.0"?&gt;
204
205&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
206 version="1.0"&gt;
207
208 &lt;xsl:output method="xhtml" encoding="iso-8859-1" indent="no"/&gt;
209
210 &lt;xsl:template match="listing"&gt;
211 &lt;html&gt;
212 &lt;head&gt;
213 &lt;title&gt;
214 Sample Directory Listing For
215 &lt;xsl:value-of select="@directory"/&gt;
216 &lt;/title&gt;
217 &lt;style&gt;
218 h1{color : white;background-color : #0086b2;}
219 h3{color : white;background-color : #0086b2;}
220 body{font-family : sans-serif,Arial,Tahoma;
221 color : black;background-color : white;}
222 b{color : white;background-color : #0086b2;}
223 a{color : black;} HR{color : #0086b2;}
224 &lt;/style&gt;
225 &lt;/head&gt;
226 &lt;body&gt;
227 &lt;h1&gt;Sample Directory Listing For
228 &lt;xsl:value-of select="@directory"/&gt;
229 &lt;/h1&gt;
230 &lt;hr size="1" /&gt;
231 &lt;table cellspacing="0"
232 width="100%"
233 cellpadding="5"
234 align="center"&gt;
235 &lt;tr&gt;
236 &lt;th align="left"&gt;Filename&lt;/th&gt;
237 &lt;th align="center"&gt;Size&lt;/th&gt;
238 &lt;th align="right"&gt;Last Modified&lt;/th&gt;
239 &lt;/tr&gt;
240 &lt;xsl:apply-templates select="entries"/&gt;
241 &lt;/table&gt;
242 &lt;xsl:apply-templates select="readme"/&gt;
243 &lt;hr size="1" /&gt;
244 &lt;h3&gt;Apache Tomcat/6.0&lt;/h3&gt;
245 &lt;/body&gt;
246 &lt;/html&gt;
247 &lt;/xsl:template&gt;
248
249
250 &lt;xsl:template match="entries"&gt;
251 &lt;xsl:apply-templates select="entry"/&gt;
252 &lt;/xsl:template&gt;
253
254 &lt;xsl:template match="readme"&gt;
255 &lt;hr size="1" /&gt;
256 &lt;pre&gt;&lt;xsl:apply-templates/&gt;&lt;/pre&gt;
257 &lt;/xsl:template&gt;
258
259 &lt;xsl:template match="entry"&gt;
260 &lt;tr&gt;
261 &lt;td align="left"&gt;
262 &lt;xsl:variable name="urlPath" select="@urlPath"/&gt;
263 &lt;a href="{$urlPath}"&gt;
264 &lt;tt&gt;&lt;xsl:apply-templates/&gt;&lt;/tt&gt;
265 &lt;/a&gt;
266 &lt;/td&gt;
267 &lt;td align="right"&gt;
268 &lt;tt&gt;&lt;xsl:value-of select="@size"/&gt;&lt;/tt&gt;
269 &lt;/td&gt;
270 &lt;td align="right"&gt;
271 &lt;tt&gt;&lt;xsl:value-of select="@date"/&gt;&lt;/tt&gt;
272 &lt;/td&gt;
273 &lt;/tr&gt;
274 &lt;/xsl:template&gt;
275
276&lt;/xsl:stylesheet&gt;
277</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>
278
279</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>
280Use web.xml in each individual webapp. See the security section of the
281Servlet specification.
282
283</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>
284 Copyright &copy; 1999-2014, Apache Software Foundation
285 </em></font></div></td></tr></table></body></html>