blob: eeadf19f1593c08772fe79170cdd58c4d11f6725 [file] [log] [blame]
Hongqing Liufd5ee812014-05-10 16:32:51 +08001<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>
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
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
162in your web.xml declaration. If you
163can understand what was just said, we will assume you can read the code
164to DefaultServlet servlet and make the appropriate adjustments. (If not,
165then that method isn't for you)
166</p>
167<p>
168You can use either <code>localXsltFile</code> or
169<code>globalXsltFile</code> and DefaultServlet will create
170an xml document and run it through an xsl transformation based
171on the values provided in <code>localXsltFile</code> and
172<code>globalXsltFile</code>. <code>localXsltFile</code> is first
173checked, followed by <code>globalXsltFile</code>, then default
174behaviors takes place.
175</p>
176
177<p>
178Format:
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 &lt;listing&gt;
181 &lt;entries&gt;
182 &lt;entry type='file|dir' urlPath='aPath' size='###' date='gmt date'&gt;
183 fileName1
184 &lt;/entry&gt;
185 &lt;entry type='file|dir' urlPath='aPath' size='###' date='gmt date'&gt;
186 fileName2
187 &lt;/entry&gt;
188 ...
189 &lt;/entries&gt;
190 &lt;readme&gt;&lt;/readme&gt;
191 &lt;/listing&gt;
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>
198The 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&lt;?xml version="1.0"?&gt;
201
202&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
203 version="1.0"&gt;
204
205 &lt;xsl:output method="xhtml" encoding="iso-8859-1" indent="no"/&gt;
206
207 &lt;xsl:template match="listing"&gt;
208 &lt;html&gt;
209 &lt;head&gt;
210 &lt;title&gt;
211 Sample Directory Listing For
212 &lt;xsl:value-of select="@directory"/&gt;
213 &lt;/title&gt;
214 &lt;style&gt;
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 &lt;/style&gt;
222 &lt;/head&gt;
223 &lt;body&gt;
224 &lt;h1&gt;Sample Directory Listing For
225 &lt;xsl:value-of select="@directory"/&gt;
226 &lt;/h1&gt;
227 &lt;hr size="1" /&gt;
228 &lt;table cellspacing="0"
229 width="100%"
230 cellpadding="5"
231 align="center"&gt;
232 &lt;tr&gt;
233 &lt;th align="left"&gt;Filename&lt;/th&gt;
234 &lt;th align="center"&gt;Size&lt;/th&gt;
235 &lt;th align="right"&gt;Last Modified&lt;/th&gt;
236 &lt;/tr&gt;
237 &lt;xsl:apply-templates select="entries"/&gt;
238 &lt;/table&gt;
239 &lt;xsl:apply-templates select="readme"/&gt;
240 &lt;hr size="1" /&gt;
241 &lt;h3&gt;Apache Tomcat/6.0&lt;/h3&gt;
242 &lt;/body&gt;
243 &lt;/html&gt;
244 &lt;/xsl:template&gt;
245
246
247 &lt;xsl:template match="entries"&gt;
248 &lt;xsl:apply-templates select="entry"/&gt;
249 &lt;/xsl:template&gt;
250
251 &lt;xsl:template match="readme"&gt;
252 &lt;hr size="1" /&gt;
253 &lt;pre&gt;&lt;xsl:apply-templates/&gt;&lt;/pre&gt;
254 &lt;/xsl:template&gt;
255
256 &lt;xsl:template match="entry"&gt;
257 &lt;tr&gt;
258 &lt;td align="left"&gt;
259 &lt;xsl:variable name="urlPath" select="@urlPath"/&gt;
260 &lt;a href="{$urlPath}"&gt;
261 &lt;tt&gt;&lt;xsl:apply-templates/&gt;&lt;/tt&gt;
262 &lt;/a&gt;
263 &lt;/td&gt;
264 &lt;td align="right"&gt;
265 &lt;tt&gt;&lt;xsl:value-of select="@size"/&gt;&lt;/tt&gt;
266 &lt;/td&gt;
267 &lt;td align="right"&gt;
268 &lt;tt&gt;&lt;xsl:value-of select="@date"/&gt;&lt;/tt&gt;
269 &lt;/td&gt;
270 &lt;/tr&gt;
271 &lt;/xsl:template&gt;
272
273&lt;/xsl:stylesheet&gt;
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>
277Use web.xml in each individual webapp. See the security section of the
278Servlet 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 &copy; 1999-2014, Apache Software Foundation
282 </em></font></div></td></tr></table></body></html>