blob: 4b68037a60d9b4024d5ce8f2dd41dbf399c5f07c [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>Apache Tomcat 7 (7.0.77) - SSI How To</title><meta name="author" content="Glenn L. Nielsen"><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 The Apache Tomcat Servlet/JSP Container
刘洪青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="http://wiki.apache.org/tomcat/FAQ">FAQ</a></li><li><a href="#comments_section">User Comments</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/TLS</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-descriptors-howto.html">16) MBeans Descriptors</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><li><a href="security-howto.html">28) Security Considerations</a></li><li><a href="windows-service-howto.html">29) Windows Service</a></li><li><a href="windows-auth-howto.html">30) Windows Authentication</a></li><li><a href="jdbc-pool.html">31) Tomcat's JDBC Pool</a></li><li><a href="web-socket-howto.html">32) WebSocket</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">Tomcat Javadocs</a></li><li><a href="servletapi/index.html">Servlet Javadocs</a></li><li><a href="jspapi/index.html">JSP 2.2 Javadocs</a></li><li><a href="elapi/index.html">EL 2.2 Javadocs</a></li><li><a href="websocketapi/index.html">WebSocket 1.1 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><li><a href="tribes/introduction.html">Tribes</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left" id="mainBody"><h1>SSI How To</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="#Introduction">Introduction</a></li><li><a href="#Installation">Installation</a></li><li><a href="#Servlet_Configuration">Servlet Configuration</a></li><li><a href="#Filter_Configuration">Filter Configuration</a></li><li><a href="#Directives">Directives</a></li><li><a href="#Variables">Variables</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="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote>
84
85<p>SSI (Server Side Includes) are directives that are placed in HTML pages,
86and evaluated on the server while the pages are being served. They let you
87add dynamically generated content to an existing HTML page, without having
88to serve the entire page via a CGI program, or other dynamic technology.
89</p>
90
91<p>Within Tomcat SSI support can be added when using Tomcat as your
92HTTP server and you require SSI support. Typically this is done
93during development when you don't want to run a web server like Apache.</p>
94
95<p>Tomcat SSI support implements the same SSI directives as Apache. See the
96<a href="http://httpd.apache.org/docs/howto/ssi.html#basicssidirectives">
97Apache Introduction to SSI</a> for information on using SSI directives.</p>
98
99<p>SSI support is available as a servlet and as a filter. You should use one
100or the other to provide SSI support but not both.</p>
101
102<p>Servlet based SSI support is implemented using the class
103<code>org.apache.catalina.ssi.SSIServlet</code>. Traditionally, this servlet
104is mapped to the URL pattern "*.shtml".</p>
105
106<p>Filter based SSI support is implemented using the class
107<code>org.apache.catalina.ssi.SSIFilter</code>. Traditionally, this filter
108is mapped to the URL pattern "*.shtml", though it can be mapped to "*" as
109it will selectively enable/disable SSI processing based on mime types. The
110contentType init param allows you to apply SSI processing to JSP pages,
111javascript, or any other content you wish.</p>
112<p>By default SSI support is disabled in Tomcat.</p>
113</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Installation"><strong>Installation</strong></a></font></td></tr><tr><td><blockquote>
114
115<p><strong>CAUTION</strong> - SSI directives can be used to execute programs
116external to the Tomcat JVM. If you are using the Java SecurityManager this
117will bypass your security policy configuration in <code>catalina.policy.</code>
118</p>
119
120<p>To use the SSI servlet, remove the XML comments from around the SSI servlet
121and servlet-mapping configuration in
122<code>$CATALINA_BASE/conf/web.xml</code>.</p>
123
124<p>To use the SSI filter, remove the XML comments from around the SSI filter
125and filter-mapping configuration in
126<code>$CATALINA_BASE/conf/web.xml</code>.</p>
127
128<p>Only Contexts which are marked as privileged may use SSI features (see the
129privileged property of the Context element).</p>
130
131</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Servlet Configuration"><!--()--></a><a name="Servlet_Configuration"><strong>Servlet Configuration</strong></a></font></td></tr><tr><td><blockquote>
132
133<p>There are several servlet init parameters which can be used to
134configure the behaviour of the SSI servlet.
135<ul>
136<li><strong>buffered</strong> - Should output from this servlet be buffered?
137(0=false, 1=true) Default 0 (false).</li>
138<li><strong>debug</strong> - Debugging detail level for messages logged
139by this servlet. Default 0.</li>
140<li><strong>expires</strong> - The number of seconds before a page with SSI
141directives will expire. Default behaviour is for all SSI directives to be
142evaluated for every request.</li>
143<li><strong>isVirtualWebappRelative</strong> - Should "virtual" SSI directive
144paths be interpreted as relative to the context root, instead of the server
145root? Default false.</li>
146<li><strong>inputEncoding</strong> - The encoding to be assumed for SSI
147resources if one cannot be determined from the resource itself. Default is
148the default platform encoding.</li>
149<li><strong>outputEncoding</strong> - The encoding to be used for the result
150of the SSI processing. Default is UTF-8.</li>
151<li><strong>allowExec</strong> - Is the exec command enabled? Default is
152false.</li>
153</ul>
154</p>
155
156</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Filter Configuration"><!--()--></a><a name="Filter_Configuration"><strong>Filter Configuration</strong></a></font></td></tr><tr><td><blockquote>
157
158<p>There are several filter init parameters which can be used to
159configure the behaviour of the SSI filter.
160<ul>
161<li><strong>contentType</strong> - A regex pattern that must be matched before
162SSI processing is applied. When crafting your own pattern, don't forget that a
163mime content type may be followed by an optional character set in the form
164"mime/type; charset=set" that you must take into account. Default is
165"text/x-server-parsed-html(;.*)?".</li>
166<li><strong>debug</strong> - Debugging detail level for messages logged
167by this servlet. Default 0.</li>
168<li><strong>expires</strong> - The number of seconds before a page with SSI
169directives will expire. Default behaviour is for all SSI directives to be
170evaluated for every request.</li>
171<li><strong>isVirtualWebappRelative</strong> - Should "virtual" SSI directive
172paths be interpreted as relative to the context root, instead of the server
173root? Default false.</li>
174<li><strong>allowExec</strong> - Is the exec command enabled? Default is
175false.</li>
176</ul>
177</p>
178
179</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Directives"><strong>Directives</strong></a></font></td></tr><tr><td><blockquote>
180<p>Server Side Includes are invoked by embedding SSI directives in an HTML document
181 whose type will be processed by the SSI servlet. The directives take the form of an HTML
182 comment. The directive is replaced by the results of interpreting it before sending the
183 page to the client. The general form of a directive is: </p>
184<p> <code>&lt;!--#directive [parm=value] --&gt;</code></p>
185<p>The directives are:
186<ul>
187<li>
188<strong>config</strong> - <code>&lt;!--#config timefmt="%B %Y" --&gt;</code>
189Used to set the format of dates and other items processed by SSI
190</li>
191<li>
192<strong>echo</strong> - <code>&lt;!--#echo var="VARIABLE_NAME" --&gt;</code>
193will be replaced by the value of the variable.
194</li>
195<li>
196<strong>exec</strong> - Used to run commands on the host system.
197</li>
198<li>
199<strong>include</strong> - <code>&lt;!--#include virtual="file-name" --&gt;</code>
200inserts the contents
201</li>
202<li>
203<strong>flastmod</strong> - <code>&lt;!--#flastmod file="filename.shtml" --&gt;</code>
204Returns the time that a file was lost modified.
205</li>
206<li>
207<strong>fsize</strong> - <code>&lt;!--#fsize file="filename.shtml" --&gt;</code>
208Returns the size of a file.
209</li>
210<li>
211<strong>printenv</strong> - <code>&lt;!--#printenv --&gt;</code>
212Returns the list of all the defined variables.
213</li>
214<li>
215<strong>set</strong> - <code>&lt;!--#set var="foo" value="Bar" --&gt;</code>
刘洪青6266f992017-05-15 21:21:03 +0800216is used to assign a value to a user-defined variable.
Hongqing Liufd5ee812014-05-10 16:32:51 +0800217</li>
218<li>
219<strong>if elif endif else</strong> - Used to create conditional sections. For example:</li>
220<code>&lt;!--#config timefmt="%A" --&gt;<br>
221 &lt;!--#if expr="$DATE_LOCAL = /Monday/" --&gt;<br>
222 &lt;p&gt;Meeting at 10:00 on Mondays&lt;/p&gt;<br>
223 &lt;!--#elif expr="$DATE_LOCAL = /Friday/" --&gt;<br>
224 &lt;p&gt;Turn in your time card&lt;/p&gt;<br>
225 &lt;!--#else --&gt;<br>
226 &lt;p&gt;Yoga class at noon.&lt;/p&gt;<br>
227 &lt;!--#endif --&gt;</code>
228 </ul>
229</p>
230See the
231<p> <a href="http://httpd.apache.org/docs/howto/ssi.html#basicssidirectives">
232Apache Introduction to SSI</a> for more information on using SSI directives.</p>
233</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Variables"><strong>Variables</strong></a></font></td></tr><tr><td><blockquote>
234<p>The SSI servlet currently implements the following variables:
235</p>
236<table border="1">
237<tr>
238<th>Variable Name</th>
239<th>Description</th>
240</tr>
241
242<tr>
243<td>AUTH_TYPE</td>
244<td>
245 The type of authentication used for this user: BASIC, FORM, etc.</td>
246</tr>
247
248<tr>
249<td>CONTENT_LENGTH</td>
250<td>
刘洪青6266f992017-05-15 21:21:03 +0800251 The length of the data (in bytes or the number of
Hongqing Liufd5ee812014-05-10 16:32:51 +0800252 characters) passed from a form.</td>
253</tr>
254
255<tr>
256<td>CONTENT_TYPE</td>
257<td>
258 The MIME type of the query data, such as "text/html".</td>
259</tr>
260
261<tr>
262<td>DATE_GMT</td>
263<td>
264Current date and time in GMT</td>
265</tr>
266
267<tr>
268<td>DATE_LOCAL</td>
269<td>
270Current date and time in the local time zone</td>
271</tr>
272<tr>
273<td>DOCUMENT_NAME</td>
274<td>
275The current file</td>
276</tr>
277<tr>
278<td>DOCUMENT_URI</td>
279<td>
280Virtual path to the file</td>
281</tr>
282
283<tr>
284<td>GATEWAY_INTERFACE</td>
285<td>
刘洪青6266f992017-05-15 21:21:03 +0800286 The revision of the Common Gateway Interface that the
Hongqing Liufd5ee812014-05-10 16:32:51 +0800287 server uses if enabled: "CGI/1.1".</td>
288</tr>
289
290<tr>
291<td>HTTP_ACCEPT</td>
292<td>
293 A list of the MIME types that the client can accept.</td>
294</tr>
295
296<tr>
297<td>HTTP_ACCEPT_ENCODING</td>
298<td>
299 A list of the compression types that the client can accept.</td>
300</tr>
301
302<tr>
303<td>HTTP_ACCEPT_LANGUAGE</td>
304<td>
305 A list of the languages that the client can accept.</td>
306</tr>
307<tr>
308<td>HTTP_CONNECTION</td>
309<td>
310 The way that the connection from the client is being managed:
311 "Close" or "Keep-Alive".</td>
312</tr>
313<tr>
314<td>HTTP_HOST</td>
315<td>
316 The web site that the client requested.</td>
317</tr>
318<tr>
319<td>HTTP_REFERER</td>
320<td>
321 The URL of the document that the client linked from.</td>
322</tr>
323<tr>
324<td>HTTP_USER_AGENT</td>
325<td>
326 The browser the client is using to issue the request.</td>
327</tr>
328<tr>
329<td>LAST_MODIFIED</td>
330<td>
331Last modification date and time for current file</td>
332</tr>
333<tr>
334<td>PATH_INFO</td>
335<td>
336 Extra path information passed to a servlet.</td>
337</tr>
338<tr>
339<td>PATH_TRANSLATED</td>
340<td>
341 The translated version of the path given by the
342 variable PATH_INFO.</td>
343</tr>
344<tr>
345<td>QUERY_STRING</td>
346<td>
347The query string that follows the "?" in the URL.
348</td>
349</tr>
350<tr>
351<td>QUERY_STRING_UNESCAPED</td>
352<td>
刘洪青6266f992017-05-15 21:21:03 +0800353Undecoded query string with all shell metacharacters escaped
Hongqing Liufd5ee812014-05-10 16:32:51 +0800354with "\"</td>
355</tr>
356<tr>
357<td>REMOTE_ADDR</td>
358<td>
359 The remote IP address of the user making the request.</td>
360</tr>
361<tr>
362<td>REMOTE_HOST</td>
363<td>
364 The remote hostname of the user making the request.</td>
365</tr>
366<tr>
367<td>REMOTE_PORT</td>
368<td>
369 The port number at remote IP address of the user making the request.</td>
370</tr>
371<tr>
372<td>REMOTE_USER</td>
373<td>
374 The authenticated name of the user.</td>
375</tr>
376<tr>
377<td>REQUEST_METHOD</td>
378<td>
379 The method with which the information request was
380 issued: "GET", "POST" etc.</td>
381</tr>
382<tr>
383<td>REQUEST_URI</td>
384<td>
385 The web page originally requested by the client.</td>
386</tr>
387<tr>
388<td>SCRIPT_FILENAME</td>
389<td>
390 The location of the current web page on the server.</td>
391</tr>
392<tr>
393<td>SCRIPT_NAME</td>
394<td>
395 The name of the web page.</td>
396</tr>
397<tr>
398<td>SERVER_ADDR</td>
399<td>
400 The server's IP address.</td>
401</tr>
402<tr>
403<td>SERVER_NAME</td>
404<td>
405 The server's hostname or IP address.</td>
406</tr>
407<tr>
408<td>SERVER_PORT</td>
409<td>
410 The port on which the server received the request.</td>
411</tr>
412<tr>
413<td>SERVER_PROTOCOL</td>
414<td>
415 The protocol used by the server. E.g. "HTTP/1.1".</td>
416</tr>
417<tr>
418<td>SERVER_SOFTWARE</td>
419<td>
刘洪青6266f992017-05-15 21:21:03 +0800420 The name and version of the server software that is
Hongqing Liufd5ee812014-05-10 16:32:51 +0800421 answering the client request.</td>
422</tr>
423<tr>
424<td>UNIQUE_ID</td>
425<td>
426 A token used to identify the current session if one
427 has been established.</td>
428</tr>
429</table>
刘洪青6266f992017-05-15 21:21:03 +0800430</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
431 on improving documentation for Apache Tomcat.<br><br>
432 If you have trouble and need help, read
433 <a href="http://tomcat.apache.org/findhelp.html">Find Help</a> page
434 and ask your question on the tomcat-users
435 <a href="http://tomcat.apache.org/lists.html">mailing list</a>.
436 Do not ask such questions here. This is not a Q&amp;A section.<br><br>
437 The Apache Comments System is explained <a href="./comments.html">here</a>.
438 Comments may be removed by our moderators if they are either
439 implemented or considered invalid/off-topic.</p><script type="text/javascript"><!--//--><![CDATA[//><!--
440 var comments_shortname = 'tomcat';
441 var comments_identifier = 'http://tomcat.apache.org/tomcat-7.0-doc/ssi-howto.html';
442 (function(w, d) {
443 if (w.location.hostname.toLowerCase() == "tomcat.apache.org") {
444 d.write('<div id="comments_thread"><\/div>');
445 var s = d.createElement('script');
446 s.type = 'text/javascript';
447 s.async = true;
448 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
449 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
450 }
451 else {
452 d.write('<div id="comments_thread"><strong>Comments are disabled for this page at the moment.<\/strong><\/div>');
453 }
454 })(window, document);
455 //--><!]]></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>
456 Copyright &copy; 1999-2017, Apache Software Foundation
Hongqing Liufd5ee812014-05-10 16:32:51 +0800457 </em></font></div></td></tr></table></body></html>