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