source: nutchez-0.1/tomcat/webapps/docs/printer/default-servlet.html @ 77

Last change on this file since 77 was 66, checked in by waue, 16 years ago

NutchEz - an easy way to nutch

File size: 14.9 KB
RevLine 
[66]1<html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Apache Tomcat 6.0 - Default Servlet Reference</title><meta value="Tim Funk" name="author"><meta value="funkman@apache.org" name="email"></head><body vlink="#525D76" alink="#525D76" link="#525D76" text="#000000" bgcolor="#ffffff"><table cellspacing="0" width="100%" border="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="http://tomcat.apache.org/"><img border="0" alt="
2      The Apache Tomcat Servlet/JSP Container
3    " align="right" src="./../images/tomcat.gif"></a></td><td><font face="arial,helvetica,sanserif"><h1>Apache Tomcat 6.0</h1></font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img border="0" alt="Apache Logo" align="right" src="./../images/asf-logo.gif"></a></td></tr></table><table cellspacing="4" width="100%" border="0"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr size="1" noshade></td></tr><tr><!--RIGHT SIDE MAIN BODY--><td align="left" valign="top" width="80%"><table cellspacing="4" width="100%" border="0"><tr><td valign="top" align="left"><h1>Apache Tomcat 6.0</h1><h2>Default Servlet Reference</h2></td><td nowrap="true" valign="top" align="right"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote>
4
5This discusses different ways to manipulate the default servlet. Topics are
6<ul>
7  <li><a href="#what">What is the DefaultServlet?</a></li>
8  <li><a href="#where">Where is it declared?</a></li>
9  <li><a href="#change">What can I change?</a></li>
10  <li><a href="#dir">How do I customize directory listings?</a></li>
11  <li><a href="#secure">How do I secure directory listings?</a></li>
12
13</ul>
14
15</blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="What is the DefaultServlet"><strong>What is the DefaultServlet</strong></a></font></td></tr><tr><td><blockquote>
16<a name="what"></a>
17The default servlet is the servlet which serves static resources as well
18as serves the directory listings (if directory listings are enabled).
19
20</blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Where is it declared?"><strong>Where is it declared?</strong></a></font></td></tr><tr><td><blockquote>
21<a name="where"></a>
22It is declared globally in <i>$CATALINA_BASE/conf/web.xml</i>.
23By default here is it's declaration:
24<div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre>
25    &lt;servlet&gt;
26        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
27        &lt;servlet-class&gt;
28          org.apache.catalina.servlets.DefaultServlet
29        &lt;/servlet-class&gt;
30        &lt;init-param&gt;
31            &lt;param-name&gt;debug&lt;/param-name&gt;
32            &lt;param-value&gt;0&lt;/param-value&gt;
33        &lt;/init-param&gt;
34        &lt;init-param&gt;
35            &lt;param-name&gt;listings&lt;/param-name&gt;
36            &lt;param-value&gt;true&lt;/param-value&gt;
37        &lt;/init-param&gt;
38        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
39    &lt;/servlet&gt;
40
41...
42
43    &lt;servlet-mapping&gt;
44        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
45        &lt;url-pattern&gt;/&lt;/url-pattern&gt;
46    &lt;/servlet-mapping&gt;
47
48</pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td></tr></table></div>
49
50So by default, the default servlet is loaded at webapp startup and
51directory listings are enabled and debugging is turned off.
52</blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="What can I change?"><strong>What can I change?</strong></a></font></td></tr><tr><td><blockquote>
53<a name="change"></a>
54The DefaultServlet allows the following initParamters:
55
56<table border="1">
57  <tr>
58    <th valign="top">debug</th>
59    <td valign="top">
60        Debugging level. It is not very useful unless you are a tomcat
61        developer. As
62        of this writing, useful values are 0, 1, 11, 1000.
63    </td>
64  </tr>
65  <tr>
66    <th valign="top">listings</th>
67    <td valign="top">
68        If no welcome file is present, can a directory listing be
69        shown?
70        value may be <b>true</b> or <b>false</b>
71        <br>
72        Welcome files are part of the servlet api.
73        <br>
74        <b>WARNING:</b> Listings of directories containing many entries are
75        expensive. Multiple requests for large directory listings can consume
76        significant proportions of server resources.
77    </td>
78  </tr>
79  <tr>
80    <th valign="top">readmeFile</th>
81    <td valign="top">
82        If a directory listing is presented, a readme file may also
83        be presented with the listing. This file is inserted as is
84        so it may contain HTML. default value is null
85    </td>
86  </tr>
87  <tr>
88    <th valign="top">globalXsltFile</th>
89    <td valign="top">
90        If you wish to customize your directory listing, you
91        can use an XSL transformation. This value is an absolute
92        file name which be used for all direcotory listings.
93        This can be disabled by per webapp by also declaring the
94        default servlet in your local webapp's web.xml. The format
95        of the xml is shown below.
96    </td>
97  </tr>
98  <tr>
99    <th valign="top">localXsltFile</th>
100    <td valign="top">
101        You may also customize your directory listing by directory by
102        configuring <code>localXsltFile</code>. This should be a relative
103        file name in the directory where the listing will take place.
104        This overrides <code>globalXsltFile</code>. If this value
105        is present but a file does not exist, then
106        <code>globalXsltFile</code> will be used. If
107        <code>globalXsltFile</code> does not exist, then the default
108        directory listing will be shown.
109    </td>
110  </tr>
111  <tr>
112    <th valign="top">input</th>
113    <td valign="top">
114        Input buffer size (in bytes) when reading
115        resources to be served.  [2048]
116    </td>
117  </tr>
118  <tr>
119    <th valign="top">output</th>
120    <td valign="top">
121        Output buffer size (in bytes) when writing
122        resources to be served.  [2048]
123    </td>
124  </tr>
125  <tr>
126    <th valign="top">readonly</th>
127    <td valign="top">
128        Is this context "read only", so HTTP commands like PUT and
129        DELETE are rejected?  [true]
130    </td>
131  </tr>
132  <tr>
133    <th valign="top">fileEncoding</th>
134    <td valign="top">
135        File encoding to be used when reading static resources.
136        [platform default]
137    </td>
138  </tr>
139  <tr>
140    <th valign="top">sendfileSize</th>
141    <td valign="top">
142        If the connector used supports sendfile, this represents the minimal
143        file size in KB for which sendfile will be used. Use a negative value
144        to always disable sendfile. [48]
145    </td>
146  </tr>
147
148</table>
149</blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="How do I customize directory listings?"><strong>How do I customize directory listings?</strong></a></font></td></tr><tr><td><blockquote>
150<a name="dir"></a>
151<p>You can override DefaultServlet with you own implementation and use that
152in your web.xml declaration. If you
153can undertand what was just said, we will assume yo can read the code
154to DefaultServlet servlet and make the appropriate adjustments. (If not,
155then that method isn't for you)
156</p>
157<p>
158You can use either  <code>localXsltFile</code> or
159<code>globalXsltFile</code> and DefaultServlet will create
160an xml document and run it through an xsl transformation based
161on the values provided in <code>localXsltFile</code> and
162<code>globalXsltFile</code>. <code>localXsltFile</code> is first
163checked, followed by <code>globalXsltFile</code>, then default
164behaviors takes place.
165</p>
166
167<p>
168Format:
169<div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre>
170    &lt;listing&gt;
171     &lt;entries&gt;
172      &lt;entry type='file|dir' urlPath='aPath' size='###' date='gmt date'&gt;
173        fileName1
174      &lt;/entry&gt;
175      &lt;entry type='file|dir' urlPath='aPath' size='###' date='gmt date'&gt;
176        fileName2
177      &lt;/entry&gt;
178      ...
179     &lt;/entries&gt;
180     &lt;readme&gt;&lt;/readme&gt;
181    &lt;/listing&gt;
182</pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td></tr></table></div>
183<ul>
184  <li>size will be missing if <code>type='dir'</code></li>
185  <li>Readme is a CDATA entry</li>
186</ul>
187</p>
188The following is a sample xsl file which mimics the default tomcat behavior:
189<div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre>
190&lt;?xml version="1.0"?&gt;
191
192&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
193  version="1.0"&gt;
194
195  &lt;xsl:output method="xhtml" encoding="iso-8859-1" indent="no"/&gt;
196
197  &lt;xsl:template match="listing"&gt;
198   &lt;html&gt;
199    &lt;head&gt;
200      &lt;title&gt;
201        Sample Directory Listing For
202        &lt;xsl:value-of select="@directory"/&gt;
203      &lt;/title&gt;
204      &lt;style&gt;
205        h1{color : white;background-color : #0086b2;}
206        h3{color : white;background-color : #0086b2;}
207        body{font-family : sans-serif,Arial,Tahoma;
208             color : black;background-color : white;}
209        b{color : white;background-color : #0086b2;}
210        a{color : black;} HR{color : #0086b2;}
211      &lt;/style&gt;
212    &lt;/head&gt;
213    &lt;body&gt;
214      &lt;h1&gt;Sample Directory Listing For
215            &lt;xsl:value-of select="@directory"/&gt;
216      &lt;/h1&gt;
217      &lt;hr size="1" /&gt;
218      &lt;table cellspacing="0"
219                  width="100%"
220            cellpadding="5"
221                  align="center"&gt;
222        &lt;tr&gt;
223          &lt;th align="left"&gt;Filename&lt;/th&gt;
224          &lt;th align="center"&gt;Size&lt;/th&gt;
225          &lt;th align="right"&gt;Last Modified&lt;/th&gt;
226        &lt;/tr&gt;
227        &lt;xsl:apply-templates select="entries"/&gt;
228        &lt;/table&gt;
229      &lt;xsl:apply-templates select="readme"/&gt;
230      &lt;hr size="1" /&gt;
231      &lt;h3&gt;Apache Tomcat/6.0&lt;/h3&gt;
232    &lt;/body&gt;
233   &lt;/html&gt;
234  &lt;/xsl:template&gt;
235
236
237  &lt;xsl:template match="entries"&gt;
238    &lt;xsl:apply-templates select="entry"/&gt;
239  &lt;/xsl:template&gt;
240
241  &lt;xsl:template match="readme"&gt;
242    &lt;hr size="1" /&gt;
243    &lt;pre&gt;&lt;xsl:apply-templates/&gt;&lt;/pre&gt;
244  &lt;/xsl:template&gt;
245
246  &lt;xsl:template match="entry"&gt;
247    &lt;tr&gt;
248      &lt;td align="left"&gt;
249        &lt;xsl:variable name="urlPath" select="@urlPath"/&gt;
250        &lt;a href="{$urlPath}"&gt;
251          &lt;tt&gt;&lt;xsl:apply-templates/&gt;&lt;/tt&gt;
252        &lt;/a&gt;
253      &lt;/td&gt;
254      &lt;td align="right"&gt;
255        &lt;tt&gt;&lt;xsl:value-of select="@size"/&gt;&lt;/tt&gt;
256      &lt;/td&gt;
257      &lt;td align="right"&gt;
258        &lt;tt&gt;&lt;xsl:value-of select="@date"/&gt;&lt;/tt&gt;
259      &lt;/td&gt;
260    &lt;/tr&gt;
261  &lt;/xsl:template&gt;
262
263&lt;/xsl:stylesheet&gt;
264</pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./../images/void.gif"></td></tr></table></div>
265
266</blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="How do I secure directory listings?"><strong>How do I secure directory listings?</strong></a></font></td></tr><tr><td><blockquote>
267<a name="secure"></a>
268Use web.xml in each individual webapp. See the security section of the
269Servlet specification.
270
271</blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr size="1" noshade></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font size="-1" color="#525D76"><em>
272        Copyright &copy; 1999-2008, Apache Software Foundation
273        </em></font></div></td></tr></table></body></html>
Note: See TracBrowser for help on using the repository browser.