blob: 7de9c87e6e75bb650f7c9873dceb5dd9e1cfb2db [file] [log] [blame]
刘洪青6266f992017-05-15 21:21:03 +08001<html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Catalina Functional Specifications (7.0.77) - Default Servlet</title><meta name="author" content="Craig McClanahan"><style type="text/css" media="print">
2 .noPrint {display: none;}
3 td#mainBody {width: 100%;}
4</style><style type="text/css">
5code {background-color:rgb(224,255,255);padding:0 0.1em;}
6code.attributeName, code.propertyName {background-color:transparent;}
7
8
9table {
10 border-collapse: collapse;
11 text-align: left;
12}
13table *:not(table) {
14 /* Prevent border-collapsing for table child elements like <div> */
15 border-collapse: separate;
16}
17
18th {
19 text-align: left;
20}
21
22
23div.codeBox pre code, code.attributeName, code.propertyName, code.noHighlight, .noHighlight code {
24 background-color: transparent;
25}
26div.codeBox {
27 overflow: auto;
28 margin: 1em 0;
29}
30div.codeBox pre {
31 margin: 0;
32 padding: 4px;
33 border: 1px solid #999;
34 border-radius: 5px;
35 background-color: #eff8ff;
36 display: table; /* To prevent <pre>s from taking the complete available width. */
37 /*
38 When it is officially supported, use the following CSS instead of display: table
39 to prevent big <pre>s from exceeding the browser window:
40 max-width: available;
41 width: min-content;
42 */
43}
44
45div.codeBox pre.wrap {
46 white-space: pre-wrap;
47}
48
49
50table.defaultTable tr, table.detail-table tr {
51 border: 1px solid #CCC;
52}
53
54table.defaultTable tr:nth-child(even), table.detail-table tr:nth-child(even) {
55 background-color: #FAFBFF;
56}
57
58table.defaultTable tr:nth-child(odd), table.detail-table tr:nth-child(odd) {
59 background-color: #EEEFFF;
60}
61
62table.defaultTable th, table.detail-table th {
63 background-color: #88b;
64 color: #fff;
65}
66
67table.defaultTable th, table.defaultTable td, table.detail-table th, table.detail-table td {
68 padding: 5px 8px;
69}
70
71
72p.notice {
73 border: 1px solid rgb(255, 0, 0);
74 background-color: rgb(238, 238, 238);
75 color: rgb(0, 51, 102);
76 padding: 0.5em;
77 margin: 1em 2em 1em 1em;
78}
79</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="
Hongqing Liufd5ee812014-05-10 16:32:51 +080080 Catalina Functional Specifications
刘洪青6266f992017-05-15 21:21:03 +080081 " border="0"></a></td><td><h1><font face="arial,helvetica,sanserif">Apache Tomcat 7</font></h1><font face="arial,helvetica,sanserif">Version 7.0.77, Mar 28 2017</font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img src="../images/asf-logo.svg" align="right" alt="Apache Logo" border="0" style="width: 266px;height: 83px;"></a></td></tr></table><table border="0" width="100%" cellspacing="4"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><tr><!--LEFT SIDE NAVIGATION--><td width="20%" valign="top" nowrap class="noPrint"><p><strong>Links</strong></p><ul><li><a href="../index.html">Docs Home</a></li><li><a href="index.html">Functional Specs</a></li><li><a href="http://wiki.apache.org/tomcat/FAQ">FAQ</a></li><li><a href="#comments_section">User Comments</a></li></ul><p><strong>Administrative Apps</strong></p><ul><li><a href="fs-admin-apps.html">Overall Requirements</a></li><li><a href="mbean-names.html">Tomcat MBean Names</a></li><li><a href="fs-admin-objects.html">Administered Objects</a></li><li><a href="fs-admin-opers.html">Supported Operations</a></li></ul><p><strong>Internal Servlets</strong></p><ul><li><a href="fs-default.html">Default Servlet</a></li></ul><p><strong>Realm Implementations</strong></p><ul><li><a href="fs-jdbc-realm.html">JDBC Realm</a></li><li><a href="fs-jndi-realm.html">JNDI Realm</a></li><li><a href="fs-memory-realm.html">Memory Realm</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left" id="mainBody"><h1>Default Servlet</h1><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 +080082<ul><li><a href="#Overview">Overview</a><ol><li><a href="#Introduction">Introduction</a></li><li><a href="#External_Specifications">External Specifications</a></li><li><a href="#Implementation_Requirements">Implementation Requirements</a></li></ol></li><li><a href="#Dependencies">Dependencies</a><ol><li><a href="#Environmental_Dependencies">Environmental Dependencies</a></li><li><a href="#Container_Dependencies">Container Dependencies</a></li></ol></li><li><a href="#Functionality">Functionality</a><ol><li><a href="#Initialization_Functionality">Initialization Functionality</a></li><li><a href="#Per-Request_Functionality">Per-Request Functionality</a></li><li><a href="#Finalization_Functionality">Finalization Functionality</a></li></ol></li><li><a href="#Testable_Assertions">Testable Assertions</a></li></ul>
83</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Overview"><strong>Overview</strong></a></font></td></tr><tr><td><blockquote>
84
85
86 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote>
87
88 <p>The purpose of the <strong>Default Servlet</strong> is to serve
89 static resources of a web application in response to client requests.
90 As the name implies, it is generally configured as the "default"
91 servlet for a web application, by being mapped to a URL pattern "/".</p>
92
93 </blockquote></td></tr></table>
94
95
96 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="External Specifications"><!--()--></a><a name="External_Specifications"><strong>External Specifications</strong></a></font></td></tr><tr><td><blockquote>
97
98 <p>The following external specifications have provisions which
99 partially define the correct behavior of the default servlet:</p>
100 <ul>
101 <li><a href="http://java.sun.com/products/servlet/download.html">
102 Servlet Specification</a> (Version 2.3 PFD2)</li>
103 <li><a href="http://www.rfc-editor.org/rfc/rfc2046.txt">Multipurpose
104 Internet Mail Extensions (MIME) Part Two: Media Types</a></li>
105 <li><a href="http://www.rfc-editor.org/rfc/rfc2616.txt">Hypertext
106 Transfer Protocol -- HTTP/1.1</a></li>
107 </ul>
108
109 </blockquote></td></tr></table>
110
111
112 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Implementation Requirements"><!--()--></a><a name="Implementation_Requirements"><strong>Implementation Requirements</strong></a></font></td></tr><tr><td><blockquote>
113
114 <p>The implementation of this functionality shall conform to the
115 following requirements:</p>
116 <ul>
117 <li>Must be implemented as a servlet.</li>
118 <li>Must support configurable parameters for debugging detail level,
119 input buffer size, output buffer size, whether or not to produce
120 directory listings when no welcome file is present, and whether or not
121 modifications are supported via DELETE and PUT.</li>
122 <li>Log debugging and operational messages (suitably internationalized)
123 via the <code>getServletContext().log()</code> method.</li>
124 </ul>
125
126 </blockquote></td></tr></table>
127
128
129</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Dependencies"><strong>Dependencies</strong></a></font></td></tr><tr><td><blockquote>
130
131
132 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Environmental Dependencies"><!--()--></a><a name="Environmental_Dependencies"><strong>Environmental Dependencies</strong></a></font></td></tr><tr><td><blockquote>
133
134 <p>The following environmental dependencies must be met in order for
135 the default servlet to operate correctly:</p>
136 <ul>
137 <li>The default servlet must be registered in the application deployment
138 descriptor (or the default deployment descriptor in file
139 <code>$CATALINA_BASE/conf/web.xml</code>) using a "default servlet"
140 servlet mapping, signified by URL pattern "/".</li>
141 </ul>
142
143 </blockquote></td></tr></table>
144
145
146 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Container Dependencies"><!--()--></a><a name="Container_Dependencies"><strong>Container Dependencies</strong></a></font></td></tr><tr><td><blockquote>
147
148 <p>Correct operation of the default servlet depends on the following
149 specific features of the surrounding container:</p>
150 <ul>
151 <li>The container shall provide a servlet context attribute that
152 lists the welcome file names that have been defined for this
153 web application.</li>
154 <li>The container shall provide a servlet context attribute that
155 contains a <code>javax.naming.directory.DirContext</code>
156 implementation representing the static resources of this
157 web application.</li>
158 </ul>
159
160 </blockquote></td></tr></table>
161
162
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="Functionality"><strong>Functionality</strong></a></font></td></tr><tr><td><blockquote>
164
165
166 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Initialization Functionality"><!--()--></a><a name="Initialization_Functionality"><strong>Initialization Functionality</strong></a></font></td></tr><tr><td><blockquote>
167
168 <p>The following processing must be performed when the <code>init()</code>
169 method of the default servlet is called:</p>
170 <ul>
171 <li>Process and sanity check configuration parameters.</li>
172 </ul>
173
174 </blockquote></td></tr></table>
175
176
177 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Per-Request Functionality"><!--()--></a><a name="Per-Request_Functionality"><strong>Per-Request Functionality</strong></a></font></td></tr><tr><td><blockquote>
178
179
180 <p>For all HTTP request methods, the resource path is determined from
181 the path information provided to this request, either as request attribute
182 <code>javax.servlet.include.path_info</code> (for a request dispatcher
183 access to a static resource) or by calling
184 <code>request.getPathInfo()</code> directly.</p>
185
186 <p>On each HTTP DELETE request processed by this servlet, the following
187 processing shall be performed:</p>
188 <ul>
189 <li>If modifications to the static resources are not allowed (set by a
190 configuration parameter), return HTTP status 403 (forbidden).</li>
191 <li>If an attempt is made to delete a resource from <code>/META-INF</code>
192 or <code>/WEB-INF</code>, return HTTP status 403 (forbidden).</li>
193 <li>If the requested resource does not exist, return HTTP status 404
194 (not found)</li>
195 <li>Unbind the resource from the directory context containing the
196 static resources for this web application. If successful, return
197 HTTP status 204 (no content). Otherwise, return HTTP status 405
198 (method not allowed).</li>
199 </ul>
200
201
202 <p>On each HTTP GET request processed by this servlet, the following
203 processing shall be performed:</p>
204 <ul>
205 <li>If the request is for a resource under <code>/META-INF</code> or
206 <code>/WEB-INF</code>, return HTTP status 404 (not found).</li>
207 <li>If the requested resource does not exist, return HTTP status 404
208 (not found).</li>
209 <li>If the requested resource is not a directory, but the resource
210 path ends in "/" or "\", return HTTP status 404 (not found).</li>
211 <li>If the requested resource is a directory:
212 <ul>
213 <li>If the request path does not end with "/", redirect to a
214 corresponding path with "/" appended so that relative references
215 in welcome files are resolved correctly.</li>
216 <li>If one of the specified welcome files exists, redirect to the
217 path for that welcome file so that it will be served explicitly.
218 </li>
219 </ul></li>
220 <li>If the request being processed contains an <code>If-Range</code>
221 header, perform the processing described in the HTTP/1.1 specification
222 to determine whether the client's information is up to date.</li>
223 <li>Determine the content type of the response, by looking up the
224 corresponding MIME type in our servlet context.</li>
225 <li>If the requested resource is a directory:
226 <ul>
227 <li>If directory listings are suppressed, return HTTP status 404
228 (not found).</li>
229 <li>Set the content type to <code>text/html</code>.</li>
230 </ul></li>
231 <li>Determine the range(s) to be returned, based on the existence of
232 any <code>If-Range</code> and <code>Range</code> headers.</li>
233 <li>If the requested resource is a directory, include an <code>ETag</code>
234 header in the response, with the value calculated based on the content
235 of the directory.</li>
236 <li>Include a <code>Last-Modified</code> header in the response documenting
237 the date/time that the resource was last modified.</li>
238 <li>Unless we are processing a HEAD request, include the appropriate
239 content (or content ranges) in the response.</li>
240 </ul>
241
242 <p>On each HTTP HEAD request processed by this servlet, the following
243 processing shall be performed:</p>
244 <ul>
245 <li>Processed identically to an HTTP GET request, except that the data
246 content is not transmitted after the headers.</li>
247 </ul>
248
249 <p>On each HTTP POST request processed by this servlet, the following
250 processing shall be performed:</p>
251 <ul>
252 <li>Processed identically to an HTTP GET request.</li>
253 </ul>
254
255
256 <p>On each HTTP PUT request processed by this servlet, the following
257 processing shall be performed:</p>
258 <ul>
259 <li>If modifications to the static resources are not allowed (set by a
260 configuration parameter), return HTTP status 403 (forbidden).</li>
261 <li>If an attempt is made to delete a resource from <code>/META-INF</code>
262 or <code>/WEB-INF</code>, return HTTP status 403 (forbidden).</li>
263 <li>Create a new resource from the body of this request.</li>
264 <li>Bind or rebind the specified path to the new resource (depending on
265 whether it currently exists or not). Return HTTP status as follows:
266 <ul>
267 <li>If binding was unsuccessful, return HTTP status 409 (conflict).
268 </li>
269 <li>If binding was successful and the resource did not previously
270 exist, return HTTP status 201 (created).</li>
271 <li>If binding was successful and the resource previously existed,
272 return HTTP status 204 (no content).</li>
273 </ul></li>
274 </ul>
275
276 </blockquote></td></tr></table>
277
278
279 <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Finalization Functionality"><!--()--></a><a name="Finalization_Functionality"><strong>Finalization Functionality</strong></a></font></td></tr><tr><td><blockquote>
280
281 <p>No specific processing is required when the <code>destroy()</code>
282 method is called:</p>
283
284 </blockquote></td></tr></table>
285
286
287</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Testable Assertions"><!--()--></a><a name="Testable_Assertions"><strong>Testable Assertions</strong></a></font></td></tr><tr><td><blockquote>
288
刘洪青6266f992017-05-15 21:21:03 +0800289 <p>In addition to the assertions implied by the functionality requirements
Hongqing Liufd5ee812014-05-10 16:32:51 +0800290 listed above, the following additional assertions shall be tested to
291 validate the behavior of the default servlet:</p>
292 <ul>
293 <li>Requests for resources that do not exist in the web application must
294 return HTTP status 404 (not found).</li>
295 <li>The default servlet must operate identically for web applications that
296 are run out of a WAR file directly, or from an unpacked directory
297 structure.</li>
298 <li>If the web application is running out of an unpacked directory
299 structure, the default servlet must recognize cases where the resource
300 has been updated through external means.</li>
301 </ul>
302
刘洪青6266f992017-05-15 21:21:03 +0800303</blockquote></td></tr></table></td></tr><tr class="noPrint"><td width="20%" valign="top" nowrap class="noPrint"></td><td width="80%" valign="top" align="left"><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="comments_section" id="comments_section"><strong>Comments</strong></a></font></td></tr><tr><td><blockquote><p class="notice"><strong>Notice: </strong>This comments section collects your suggestions
304 on improving documentation for Apache Tomcat.<br><br>
305 If you have trouble and need help, read
306 <a href="http://tomcat.apache.org/findhelp.html">Find Help</a> page
307 and ask your question on the tomcat-users
308 <a href="http://tomcat.apache.org/lists.html">mailing list</a>.
309 Do not ask such questions here. This is not a Q&amp;A section.<br><br>
310 The Apache Comments System is explained <a href="../comments.html">here</a>.
311 Comments may be removed by our moderators if they are either
312 implemented or considered invalid/off-topic.</p><script type="text/javascript"><!--//--><![CDATA[//><!--
313 var comments_shortname = 'tomcat';
314 var comments_identifier = 'http://tomcat.apache.org/tomcat-7.0-doc/funcspecs/fs-default.html';
315 (function(w, d) {
316 if (w.location.hostname.toLowerCase() == "tomcat.apache.org") {
317 d.write('<div id="comments_thread"><\/div>');
318 var s = d.createElement('script');
319 s.type = 'text/javascript';
320 s.async = true;
321 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
322 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
323 }
324 else {
325 d.write('<div id="comments_thread"><strong>Comments are disabled for this page at the moment.<\/strong><\/div>');
326 }
327 })(window, document);
328 //--><!]]></script></blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font color="#525D76" size="-1"><em>
329 Copyright &copy; 1999-2017, Apache Software Foundation
Hongqing Liufd5ee812014-05-10 16:32:51 +0800330 </em></font></div></td></tr></table></body></html>