[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 | |
---|
| 5 | This 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> |
---|
| 17 | The default servlet is the servlet which serves static resources as well |
---|
| 18 | as 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> |
---|
| 22 | It is declared globally in <i>$CATALINA_BASE/conf/web.xml</i>. |
---|
| 23 | By 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 | <servlet> |
---|
| 26 | <servlet-name>default</servlet-name> |
---|
| 27 | <servlet-class> |
---|
| 28 | org.apache.catalina.servlets.DefaultServlet |
---|
| 29 | </servlet-class> |
---|
| 30 | <init-param> |
---|
| 31 | <param-name>debug</param-name> |
---|
| 32 | <param-value>0</param-value> |
---|
| 33 | </init-param> |
---|
| 34 | <init-param> |
---|
| 35 | <param-name>listings</param-name> |
---|
| 36 | <param-value>true</param-value> |
---|
| 37 | </init-param> |
---|
| 38 | <load-on-startup>1</load-on-startup> |
---|
| 39 | </servlet> |
---|
| 40 | |
---|
| 41 | ... |
---|
| 42 | |
---|
| 43 | <servlet-mapping> |
---|
| 44 | <servlet-name>default</servlet-name> |
---|
| 45 | <url-pattern>/</url-pattern> |
---|
| 46 | </servlet-mapping> |
---|
| 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 | |
---|
| 50 | So by default, the default servlet is loaded at webapp startup and |
---|
| 51 | directory 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> |
---|
| 54 | The 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 |
---|
| 152 | in your web.xml declaration. If you |
---|
| 153 | can undertand what was just said, we will assume yo can read the code |
---|
| 154 | to DefaultServlet servlet and make the appropriate adjustments. (If not, |
---|
| 155 | then that method isn't for you) |
---|
| 156 | </p> |
---|
| 157 | <p> |
---|
| 158 | You can use either <code>localXsltFile</code> or |
---|
| 159 | <code>globalXsltFile</code> and DefaultServlet will create |
---|
| 160 | an xml document and run it through an xsl transformation based |
---|
| 161 | on the values provided in <code>localXsltFile</code> and |
---|
| 162 | <code>globalXsltFile</code>. <code>localXsltFile</code> is first |
---|
| 163 | checked, followed by <code>globalXsltFile</code>, then default |
---|
| 164 | behaviors takes place. |
---|
| 165 | </p> |
---|
| 166 | |
---|
| 167 | <p> |
---|
| 168 | Format: |
---|
| 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 | <listing> |
---|
| 171 | <entries> |
---|
| 172 | <entry type='file|dir' urlPath='aPath' size='###' date='gmt date'> |
---|
| 173 | fileName1 |
---|
| 174 | </entry> |
---|
| 175 | <entry type='file|dir' urlPath='aPath' size='###' date='gmt date'> |
---|
| 176 | fileName2 |
---|
| 177 | </entry> |
---|
| 178 | ... |
---|
| 179 | </entries> |
---|
| 180 | <readme></readme> |
---|
| 181 | </listing> |
---|
| 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> |
---|
| 188 | The 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 | <?xml version="1.0"?> |
---|
| 191 | |
---|
| 192 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
---|
| 193 | version="1.0"> |
---|
| 194 | |
---|
| 195 | <xsl:output method="xhtml" encoding="iso-8859-1" indent="no"/> |
---|
| 196 | |
---|
| 197 | <xsl:template match="listing"> |
---|
| 198 | <html> |
---|
| 199 | <head> |
---|
| 200 | <title> |
---|
| 201 | Sample Directory Listing For |
---|
| 202 | <xsl:value-of select="@directory"/> |
---|
| 203 | </title> |
---|
| 204 | <style> |
---|
| 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 | </style> |
---|
| 212 | </head> |
---|
| 213 | <body> |
---|
| 214 | <h1>Sample Directory Listing For |
---|
| 215 | <xsl:value-of select="@directory"/> |
---|
| 216 | </h1> |
---|
| 217 | <hr size="1" /> |
---|
| 218 | <table cellspacing="0" |
---|
| 219 | width="100%" |
---|
| 220 | cellpadding="5" |
---|
| 221 | align="center"> |
---|
| 222 | <tr> |
---|
| 223 | <th align="left">Filename</th> |
---|
| 224 | <th align="center">Size</th> |
---|
| 225 | <th align="right">Last Modified</th> |
---|
| 226 | </tr> |
---|
| 227 | <xsl:apply-templates select="entries"/> |
---|
| 228 | </table> |
---|
| 229 | <xsl:apply-templates select="readme"/> |
---|
| 230 | <hr size="1" /> |
---|
| 231 | <h3>Apache Tomcat/6.0</h3> |
---|
| 232 | </body> |
---|
| 233 | </html> |
---|
| 234 | </xsl:template> |
---|
| 235 | |
---|
| 236 | |
---|
| 237 | <xsl:template match="entries"> |
---|
| 238 | <xsl:apply-templates select="entry"/> |
---|
| 239 | </xsl:template> |
---|
| 240 | |
---|
| 241 | <xsl:template match="readme"> |
---|
| 242 | <hr size="1" /> |
---|
| 243 | <pre><xsl:apply-templates/></pre> |
---|
| 244 | </xsl:template> |
---|
| 245 | |
---|
| 246 | <xsl:template match="entry"> |
---|
| 247 | <tr> |
---|
| 248 | <td align="left"> |
---|
| 249 | <xsl:variable name="urlPath" select="@urlPath"/> |
---|
| 250 | <a href="{$urlPath}"> |
---|
| 251 | <tt><xsl:apply-templates/></tt> |
---|
| 252 | </a> |
---|
| 253 | </td> |
---|
| 254 | <td align="right"> |
---|
| 255 | <tt><xsl:value-of select="@size"/></tt> |
---|
| 256 | </td> |
---|
| 257 | <td align="right"> |
---|
| 258 | <tt><xsl:value-of select="@date"/></tt> |
---|
| 259 | </td> |
---|
| 260 | </tr> |
---|
| 261 | </xsl:template> |
---|
| 262 | |
---|
| 263 | </xsl:stylesheet> |
---|
| 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> |
---|
| 268 | Use web.xml in each individual webapp. See the security section of the |
---|
| 269 | Servlet 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 © 1999-2008, Apache Software Foundation |
---|
| 273 | </em></font></div></td></tr></table></body></html> |
---|