Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
771 blopes 1
<!DOCTYPE html SYSTEM "about:legacy-compat">
2
<html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="../images/docs-stylesheet.css" rel="stylesheet" type="text/css"><title>Apache Tomcat 9 Configuration Reference (9.0.112) - The Context Container</title></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="https://tomcat.apache.org/"><img alt="Tomcat Home" src="../images/tomcat.png"></a></div><div style="height: 1px;"></div><div class="asfLogo noPrint"><a href="https://www.apache.org/" target="_blank"><img src="../images/asf-logo.svg" alt="The Apache Software Foundation" style="width: 266px; height: 83px;"></a></div><h1>Apache Tomcat 9 Configuration Reference</h1><div class="versionInfo">
3
            Version 9.0.112,
4
            <time datetime="2025-11-06">Nov 6 2025</time></div><div style="height: 1px;"></div><div style="clear: left;"></div></div></div></div></header><div id="middle"><div><div id="mainLeft" class="noprint"><div><nav><div><h2>Links</h2><ul><li><a href="../index.html">Docs Home</a></li><li><a href="index.html">Config Ref. Home</a></li><li><a href="https://cwiki.apache.org/confluence/display/TOMCAT/FAQ">FAQ</a></li><li><a href="#comments_section">User Comments</a></li></ul></div><div><h2>Top Level Elements</h2><ul><li><a href="server.html">Server</a></li><li><a href="service.html">Service</a></li></ul></div><div><h2>Executors</h2><ul><li><a href="executor.html">Executor</a></li></ul></div><div><h2>Connectors</h2><ul><li><a href="http.html">HTTP/1.1</a></li><li><a href="http2.html">HTTP/2</a></li><li><a href="ajp.html">AJP</a></li></ul></div><div><h2>Containers</h2><ul><li><a href="context.html">Context</a></li><li><a href="engine.html">Engine</a></li><li><a href="host.html">Host</a></li><li><a href="cluster.html">Cluster</a></li></ul></div><div><h2>Nested Components</h2><ul><li><a href="cookie-processor.html">CookieProcessor</a></li><li><a href="credentialhandler.html">CredentialHandler</a></li><li><a href="globalresources.html">Global Resources</a></li><li><a href="jar-scanner.html">JarScanner</a></li><li><a href="jar-scan-filter.html">JarScanFilter</a></li><li><a href="listeners.html">Listeners</a></li><li><a href="loader.html">Loader</a></li><li><a href="manager.html">Manager</a></li><li><a href="realm.html">Realm</a></li><li><a href="resources.html">Resources</a></li><li><a href="sessionidgenerator.html">SessionIdGenerator</a></li><li><a href="valve.html">Valve</a></li></ul></div><div><h2>Cluster Elements</h2><ul><li><a href="cluster.html">Cluster</a></li><li><a href="cluster-manager.html">Manager</a></li><li><a href="cluster-channel.html">Channel</a></li><li><a href="cluster-membership.html">Channel/Membership</a></li><li><a href="cluster-sender.html">Channel/Sender</a></li><li><a href="cluster-receiver.html">Channel/Receiver</a></li><li><a href="cluster-interceptor.html">Channel/Interceptor</a></li><li><a href="cluster-valve.html">Valve</a></li><li><a href="cluster-deployer.html">Deployer</a></li><li><a href="cluster-listener.html">ClusterListener</a></li></ul></div><div><h2>web.xml</h2><ul><li><a href="filter.html">Filter</a></li></ul></div><div><h2>Other</h2><ul><li><a href="runtime-attributes.html">Runtime attributes</a></li><li><a href="systemprops.html">System properties</a></li><li><a href="jaspic.html">JASPIC</a></li></ul></div></nav></div></div><div id="mainRight"><div id="content"><h2>The Context Container</h2><h3 id="Table_of_Contents">Table of Contents</h3><div class="text">
5
<ul><li><a href="#Introduction">Introduction</a><ol><li><a href="#Parallel_deployment">Parallel deployment</a></li><li><a href="#Naming">Naming</a></li><li><a href="#Defining_a_context">Defining a context</a></li></ol></li><li><a href="#Attributes">Attributes</a><ol><li><a href="#Common_Attributes">Common Attributes</a></li><li><a href="#Standard_Implementation">Standard Implementation</a></li></ol></li><li><a href="#Nested_Components">Nested Components</a></li><li><a href="#Special_Features">Special Features</a><ol><li><a href="#Logging">Logging</a></li><li><a href="#Access_Logs">Access Logs</a></li><li><a href="#Automatic_Context_Configuration">Automatic Context Configuration</a></li><li><a href="#Context_Parameters">Context Parameters</a></li><li><a href="#Environment_Entries">Environment Entries</a></li><li><a href="#Lifecycle_Listeners">Lifecycle Listeners</a></li><li><a href="#Request_Filters">Request Filters</a></li><li><a href="#Resource_Definitions">Resource Definitions</a></li><li><a href="#Resource_Links">Resource Links</a></li><li><a href="#Transaction">Transaction</a></li></ol></li></ul>
6
</div><h3 id="Introduction">Introduction</h3><div class="text">
7
 
8
    <p><em>
9
    The description below uses the variable name $CATALINA_BASE to refer the
10
    base directory against which most relative paths are resolved. If you have
11
    not configured Tomcat for multiple instances by setting a CATALINA_BASE
12
    directory, then $CATALINA_BASE will be set to the value of $CATALINA_HOME,
13
    the directory into which you have installed Tomcat.
14
    </em></p>
15
 
16
  <p>The <strong>Context</strong> element represents a <em>web
17
  application</em>, which is run within a particular virtual host.
18
  Each web application is based on a <em>Web Application Archive</em>
19
  (WAR) file, or a corresponding directory containing the corresponding
20
  unpacked contents, as described in the Servlet Specification (version
21
  2.2 or later).  For more information about web application archives,
22
  you can download the
23
  <a href="https://cwiki.apache.org/confluence/display/TOMCAT/Specifications">Servlet
24
  Specification</a>, and review the Tomcat
25
  <a href="../appdev/index.html">Application Developer's Guide</a>.</p>
26
 
27
  <p>The web application used to process each HTTP request is selected
28
  by Catalina based on matching the longest possible prefix of the
29
  Request URI against the <em>context path</em> of each defined Context.
30
  Once selected, that Context will select an appropriate servlet to
31
  process the incoming request, according to the servlet mappings defined
32
  by the web application deployment.</p>
33
 
34
  <p>You may define as many <strong>Context</strong> elements as you
35
  wish.  Each such Context MUST have a unique context name within a virtual
36
  host. The context path does not need to be unique (see <em>parallel
37
  deployment</em> below). In addition, a Context must be present with a
38
  context path equal to
39
  a zero-length string.  This Context becomes the <em>default</em>
40
  web application for this virtual host, and is used to process all
41
  requests that do not match any other Context's context path.</p>
42
 
43
  <div class="subsection"><h4 id="Parallel_deployment">Parallel deployment</h4><div class="text">
44
  <p><b>You may deploy multiple versions of a web application with the same
45
  context path at the same time.</b> The rules used to match requests to a
46
  context version are as follows:
47
  </p>
48
  <ul>
49
  <li>If no session information is present in the request, use the latest
50
  version.</li>
51
  <li>If session information is present in the request, check the session
52
  manager of each version for a matching session and if one is found, use that
53
  version.</li>
54
  <li>If session information is present in the request but no matching session
55
  can be found, use the latest version.</li>
56
  </ul>
57
  <p>The <a href="host.html">Host</a> may be configured (via the
58
  <code>undeployOldVersions</code>) to remove old versions deployed in this way
59
  once they are no longer in use.</p>
60
  </div></div>
61
 
62
  <div class="subsection"><h4 id="Naming">Naming</h4><div class="text">
63
  <p>When <code>autoDeploy</code> or <code>deployOnStartup</code> operations
64
  are performed by a Host, the name and context path of the web application are
65
  derived from the name(s) of the file(s) that define(s) the web application.
66
  Consequently, the context path <strong>may not</strong> be defined in a
67
  <code>META-INF/context.xml</code> embedded in the application and there is a
68
  close relationship between the <em>context name</em>, <em>context path</em>,
69
  <em>context version</em> and the <em>base file name</em> (the name minus any
70
  <code>.war</code> or <code>.xml</code> extension) of the file.</p>
71
 
72
  <p>If no version is specified then the <em>context name</em> is always the
73
  same as the <em>context path</em>. If the <em>context path</em> is the empty
74
  string then the <em>base name</em> will be ROOT (always in upper case)
75
  otherwise the <em>base name</em> will be the <em>context path</em> with the
76
  leading '/' removed and any remaining '/' characters replaced with '#'.</p>
77
 
78
  <p>If a version is specified then the <em>context path</em> remains unchanged
79
  and both the <em>context name</em> and the <em>base name</em> have the string
80
  '##' appended to them followed by the version identifier.</p>
81
 
82
  <p>Some examples of these naming conventions are given below.</p>
83
 
84
  <table class="detail-table">
85
    <tr>
86
      <th>Context Path</th>
87
      <th>Context Version</th>
88
      <th>Context Name</th>
89
      <th>Base File Name</th>
90
      <th>Example File Names (.xml, .war &amp; directory)</th>
91
    </tr>
92
    <tr>
93
      <td>/foo</td>
94
      <td><i>None</i></td>
95
      <td>/foo</td>
96
      <td>foo</td>
97
      <td>foo.xml, foo.war, foo</td>
98
    </tr>
99
    <tr>
100
      <td>/foo/bar</td>
101
      <td><i>None</i></td>
102
      <td>/foo/bar</td>
103
      <td>foo#bar</td>
104
      <td>foo#bar.xml, foo#bar.war, foo#bar</td>
105
    </tr>
106
    <tr>
107
      <td><i>Empty String</i></td>
108
      <td><i>None</i></td>
109
      <td><i>Empty String</i></td>
110
      <td>ROOT</td>
111
      <td>ROOT.xml, ROOT.war, ROOT</td>
112
    </tr>
113
    <tr>
114
      <td>/foo</td>
115
      <td>42</td>
116
      <td>/foo##42</td>
117
      <td>foo##42</td>
118
      <td>foo##42.xml, foo##42.war, foo##42</td>
119
    </tr>
120
    <tr>
121
      <td>/foo/bar</td>
122
      <td>42</td>
123
      <td>/foo/bar##42</td>
124
      <td>foo#bar##42</td>
125
      <td>foo#bar##42.xml, foo#bar##42.war, foo#bar##42</td>
126
    </tr>
127
    <tr>
128
      <td><i>Empty String</i></td>
129
      <td>42</td>
130
      <td>##42</td>
131
      <td>ROOT##42</td>
132
      <td>ROOT##42.xml, ROOT##42.war, ROOT##42</td>
133
    </tr>
134
  </table>
135
 
136
  <p>The version component is treated as a <code>String</code> both for
137
  performance reasons and to allow flexibility in versioning schemes. String
138
  comparisons are used to determine version order. If version is not specified,
139
  it is treated as the empty string.
140
  Therefore,
141
  <code>foo.war</code> will be treated as an earlier version than
142
  <code>foo##11.war</code> and
143
  <code>foo##11.war</code> will be treated as an earlier version than
144
  <code>foo##2.war</code>. If using a purely numerical versioning scheme it is
145
  recommended that zero padding is used so that <code>foo##002.war</code> is
146
  treated as an earlier version than <code>foo##011.war</code>.
147
  </p>
148
  <p>To get the current webapp version number in a servlet you should use
149
  <code>org.apache.catalina.webappVersion</code>
150
  <a href="runtime-attributes.html">attribute</a>, like this:
151
  <code>String webappVersion =
152
  (String)request.getServletContext().getAttribute("org.apache.catalina.webappVersion");
153
  </code>
154
  </p>
155
  <p>If you want to deploy a WAR file or a directory using a context path that
156
  is not related to the base file name then one of the following options must
157
  be used to prevent double-deployment:
158
  </p>
159
  <ul>
160
  <li>Disable autoDeploy and deployOnStartup and define all
161
  <strong>Context</strong>s in server.xml</li>
162
  <li>Locate the WAR and/or directory outside of the Host's
163
      <code>appBase</code> and use a context.xml file with a
164
      <code>docBase</code> attribute to define it.</li>
165
  </ul>
166
  </div></div>
167
 
168
  <div class="subsection"><h4 id="Defining_a_context">Defining a context</h4><div class="text">
169
  <p><b>It is NOT recommended to place &lt;Context&gt; elements directly in the
170
  server.xml file.</b> This is because it makes modifying the
171
  <strong>Context</strong> configuration more invasive since the main
172
  <code>conf/server.xml</code> file cannot be reloaded without restarting
173
  Tomcat. Default <strong>Context</strong> elements (see below) will also
174
  <strong>overwrite</strong> the configuration of any &lt;Context&gt; elements
175
  placed directly in server.xml. To prevent this, the <code>override</code>
176
  attribute of the &lt;Context&gt; element defined in server.xml should be set
177
  to <code>true</code>.</p>
178
 
179
  <p>Individual <strong>Context</strong> elements may be explicitly defined:
180
  </p>
181
  <ul>
182
  <li>In an individual file at <code>/META-INF/context.xml</code> inside the
183
  application files. Optionally (based on the Host's copyXML attribute)
184
  this may be copied to
185
  <code>$CATALINA_BASE/conf/[enginename]/[hostname]/</code> and renamed to
186
  application's base file name plus a ".xml" extension.</li>
187
  <li>In individual files (with a ".xml" extension) in the
188
  <code>$CATALINA_BASE/conf/[enginename]/[hostname]/</code> directory.
189
  The context path and version will be derived from the base name of the file
190
  (the file name less the .xml extension). This file will always take precedence
191
  over any context.xml file packaged in the web application's META-INF
192
  directory.</li>
193
  <li>Inside a <a href="host.html">Host</a> element in the main
194
  <code>conf/server.xml</code>.</li>
195
  </ul>
196
 
197
  <p>Default <strong>Context</strong> elements may be defined that apply to
198
  multiple web applications. Configuration for an individual web application
199
  will override anything configured in one of these defaults. Any nested
200
  elements, e.g. &lt;Resource&gt; elements, that are defined in a default
201
  <strong>Context</strong> will be created once for each
202
  <strong>Context</strong> to which the default applies. They will <b>not</b> be
203
  shared between <strong>Context</strong> elements.
204
  </p>
205
  <ul>
206
  <li>In the <code>$CATALINA_BASE/conf/context.xml</code> file:
207
  the Context element information will be loaded by all web applications.</li>
208
  <li>In the
209
  <code>$CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default</code>
210
  file: the Context element information will be loaded by all web applications
211
  of that host.</li>
212
  </ul>
213
 
214
  <p>With the exception of server.xml, files that define <strong>Context
215
  </strong> elements may only define a single <strong>Context</strong> element.
216
  </p>
217
 
218
  <p>In addition to explicitly specified Context elements, there are
219
  several techniques by which Context elements can be created automatically
220
  for you.  See <a href="host.html#Automatic_Application_Deployment">
221
  Automatic Application Deployment</a> and
222
  <a href="host.html#User_Web_Applications">User Web Applications</a>
223
  for more information.</p>
224
 
225
  <p>To define multiple contexts that use a single WAR file or directory,
226
  use one of the options described in the <a href="#Naming">Naming</a>
227
  section above for creating a <strong>Context</strong> that has a path
228
  that is not related to the base file name.</p>
229
  </div></div>
230
</div><h3 id="Attributes">Attributes</h3><div class="text">
231
 
232
  <div class="subsection"><h4 id="Common_Attributes">Common Attributes</h4><div class="text">
233
 
234
    <p>All implementations of <strong>Context</strong>
235
    support the following attributes:</p>
236
 
237
    <table class="defaultTable"><tr><th style="width: 15%;">
238
          Attribute
239
        </th><th style="width: 85%;">
240
          Description
241
        </th></tr><tr id="Attributes_Common Attributes_allowCasualMultipartParsing"><td><code class="attributeName">allowCasualMultipartParsing</code></td><td>
242
        <p>Set to <code>true</code> if Tomcat should automatically parse
243
        multipart/form-data request bodies when HttpServletRequest.getPart*
244
        or HttpServletRequest.getParameter* is called, even when the
245
        target servlet isn't marked with the @MultipartConfig annotation
246
        (See Servlet Specification 3.0, Section 3.2 for details).
247
        Note that any setting other than <code>false</code> causes Tomcat
248
        to behave in a way that is not technically spec-compliant.
249
        The default is <code>false</code>.</p>
250
      </td></tr><tr id="Attributes_Common Attributes_allowMultipleLeadingForwardSlashInPath"><td><code class="attributeName">allowMultipleLeadingForwardSlashInPath</code></td><td>
251
        <p>Tomcat normalises sequences of multiple <code>/</code> characters in
252
        a URI to a single <code>/</code>. This is for consistency with the
253
        behaviour of file systems as URIs are often translated to file system
254
        paths. As a result, the return value of
255
        <code>HttpServletRequest#getContextPath()</code> is expected to start
256
        with multiple <code>/</code> characters for some URIs. This will cause
257
        problems if this value is used directly with
258
        <code>HttpServletResponse#sendRedirect()</code> as redirect paths that
259
        start with <code>//</code> are treated as protocol relative redirects.
260
        To avoid potential issues, Tomcat will collapse multiple leading
261
        <code>/</code> characters at the start of the return value for
262
        <code>HttpServletRequest#getContextPath()</code> to a single
263
        <code>/</code>. This attribute has a default value of <code>false</code>
264
        which enables the collapsing of multiple <code>/</code> characters. To
265
        disable this behaviour, set this attribute to <code>true</code>.</p>
266
      </td></tr><tr id="Attributes_Common Attributes_altDDName"><td><code class="attributeName">altDDName</code></td><td>
267
        <p>The absolute path to the alternative deployment descriptor for this
268
        context. This overrides the default deployment descriptor located at
269
        <code>/WEB-INF/web.xml</code>.</p>
270
      </td></tr><tr id="Attributes_Common Attributes_backgroundProcessorDelay"><td><code class="attributeName">backgroundProcessorDelay</code></td><td>
271
        <p>This value represents the delay in seconds between the
272
        invocation of the backgroundProcess method on this context and
273
        its child containers, including all wrappers.
274
        Child containers will not be invoked if their delay value is not
275
        negative (which would mean they are using their own processing
276
        thread). Setting this to a positive value will cause
277
        a thread to be spawn. After waiting the specified amount of time,
278
        the thread will invoke the backgroundProcess method on this host
279
        and all its child containers. A context will use background
280
        processing to perform session expiration and class monitoring for
281
        reloading. If not specified, the default value for this attribute is
282
        -1, which means the context will rely on the background processing
283
        thread of its parent host.</p>
284
      </td></tr><tr id="Attributes_Common Attributes_className"><td><code class="attributeName">className</code></td><td>
285
        <p>Java class name of the implementation to use.  This class must
286
        implement the <code>org.apache.catalina.Context</code> interface.
287
        If not specified, the standard value (defined below) will be used.</p>
288
      </td></tr><tr id="Attributes_Common Attributes_containerSciFilter"><td><code class="attributeName">containerSciFilter</code></td><td>
289
        <p>The regular expression that specifies which container provided SCIs
290
        should be filtered out and not used for this context. Matching uses
291
        <code>java.util.regex.Matcher.find()</code> so the regular expression
292
        only has to match a sub-string of the fully qualified class name of the
293
        container provided SCI for it to be filtered out. If not specified,
294
        no filtering will be applied.</p>
295
      </td></tr><tr id="Attributes_Common Attributes_cookies"><td><code class="attributeName">cookies</code></td><td>
296
        <p>Set to <code>true</code> if you want cookies to be used for
297
        session identifier communication if supported by the client (this
298
        is the default).  Set to <code>false</code> if you want to disable
299
        the use of cookies for session identifier communication, and rely
300
        only on URL rewriting by the application.</p>
301
      </td></tr><tr id="Attributes_Common Attributes_createUploadTargets"><td><code class="attributeName">createUploadTargets</code></td><td>
302
        <p>Set to <code>true</code> if Tomcat should attempt to create the
303
        temporary upload location specified in the <code>MultipartConfig</code>
304
        for a Servlet if the location does not already exist. If not specified,
305
        the default value of <code>false</code> will be used.</p>
306
      </td></tr><tr id="Attributes_Common Attributes_crossContext"><td><code class="attributeName">crossContext</code></td><td>
307
        <p>Set to <code>true</code> if you want calls within this application
308
        to <code>ServletContext.getContext()</code> to successfully return a
309
        request dispatcher for other web applications running on this virtual
310
        host.  Set to <code>false</code> (the default) in security
311
        conscious environments, to make <code>getContext()</code> always
312
        return <code>null</code>.</p>
313
      </td></tr><tr id="Attributes_Common Attributes_dispatchersUseEncodedPaths"><td><code class="attributeName">dispatchersUseEncodedPaths</code></td><td>
314
        <p>Controls whether paths used in calls to obtain a request dispatcher
315
        ares expected to be encoded. This affects both how Tomcat handles calls
316
        to obtain a request dispatcher as well as how Tomcat generates paths
317
        used to obtain request dispatchers internally. If not specified, the
318
        default value of <code>true</code> is used. When encoding/decoding paths
319
        for a request dispatcher, UTF-8 is always used.</p>
320
      </td></tr><tr id="Attributes_Common Attributes_docBase"><td><strong><code class="attributeName">docBase</code></strong></td><td>
321
        <p>The <em>Document Base</em> (also known as the <em>Context
322
        Root</em>) directory for this web application, or the pathname
323
        to the web application archive file (if this web application is
324
        being executed directly from the WAR file). You may specify
325
        an absolute pathname for this directory or WAR file, or a pathname
326
        that is relative to the <code>appBase</code> directory of the
327
        owning <a href="host.html">Host</a>.</p>
328
        <p>The value of this field must not be set unless the Context element is
329
        defined in server.xml or the <code>docBase</code> is not located under
330
        the <a href="host.html">Host</a>'s <code>appBase</code>.</p>
331
        <p>If a symbolic link is used for <code>docBase</code> then changes to
332
        the symbolic link will only be effective after a Tomcat restart or
333
        by undeploying and redeploying the context. A context reload is not
334
        sufficient.</p>
335
      </td></tr><tr id="Attributes_Common Attributes_encodedReverseSolidusHandling"><td><code class="attributeName">encodedReverseSolidusHandling</code></td><td>
336
        <p>When set to <code>reject</code>, an attempt to obtain a
337
        <code>RequestDispatcher</code> for a path containing a <code>%5c</code>
338
        sequence will trigger an <code>IllegalArgumentException</code>. When set
339
        to <code>decode</code>, any <code>%5c</code> sequence in the path used
340
        to obtain a <code>RequestDispatcher</code> will have that sequence
341
        decoded to <code>\</code> (and then normalized to <code>/</code>) before
342
        the <code>RequestDispatcher</code> is created. When set to
343
        <code>passthrough</code>, any <code>%5c</code> sequence in the path used
344
        to obtain a <code>RequestDispatcher</code> will remain unchanged.</p>
345
        <p>If <code>passthrough</code> is used then it is the application's
346
        responsibility to perform any further <code>%nn</code> decoding required.
347
        Any <code>%25</code> sequences (encoded <code>%</code>) in the path will
348
        also be processed with the <code>%25</code> sequence unchanged
349
        to avoid potential corruption and/or decoding failure when the path is
350
        subsequently <code>%nn</code> decoded by the application.</p>
351
        <p>If not specified, the default value is <code>decode</code>.</p>
352
      </td></tr><tr id="Attributes_Common Attributes_encodedSolidusHandling"><td><code class="attributeName">encodedSolidusHandling</code></td><td>
353
        <p>When set to <code>reject</code>, an attempt to obtain a
354
        <code>RequestDispatcher</code> for a path containing a <code>%2f</code>
355
        sequence will trigger an <code>IllegalArgumentException</code>. When set
356
        to <code>decode</code>, any <code>%2f</code> sequence in the path used
357
        to obtain a <code>RequestDispatcher</code> will have that sequence
358
        decoded to <code>/</code> before the <code>RequestDispatcher</code> is
359
        created. When set to <code>passthrough</code>, any <code>%2f</code>
360
        sequence in the path used to obtain a <code>RequestDispatcher</code>
361
        will remain unchanged.</p>
362
        <p>If <code>passthrough</code> is used then it is the application's
363
        responsibility to perform any further <code>%nn</code> decoding required.
364
        Any <code>%25</code> sequences (encoded <code>%</code>) in the path will
365
        also be processed with the <code>%25</code> sequence unchanged
366
        to avoid potential corruption and/or decoding failure when the path is
367
        subsequently <code>%nn</code> decoded by the application.</p>
368
        <p>If not specified, the default value is <code>decode</code>. This
369
        default will change to <code>reject</code> (to align with the
370
        <strong>Connector</strong>) in Tomcat 12.</p>
371
      </td></tr><tr id="Attributes_Common Attributes_failCtxIfServletStartFails"><td><code class="attributeName">failCtxIfServletStartFails</code></td><td>
372
        <p>Set to <code>true</code> to have the context fail its startup if any
373
        servlet that has load-on-startup &gt;=0 fails its own startup.</p>
374
        <p>If not specified, the attribute of the same name in the parent Host
375
        configuration is used if specified. Otherwise the default value of
376
        <code>false</code> is used.</p>
377
      </td></tr><tr id="Attributes_Common Attributes_fireRequestListenersOnForwards"><td><code class="attributeName">fireRequestListenersOnForwards</code></td><td>
378
        <p>Set to <code>true</code> to fire any configured
379
        ServletRequestListeners  when Tomcat forwards a request. This is
380
        primarily of use to users of CDI frameworks that use
381
        ServletRequestListeners to configure the necessary environment for a
382
        request. If not specified, the default value of <code>false</code> is
383
        used.</p>
384
      </td></tr><tr id="Attributes_Common Attributes_logEffectiveWebXml"><td><code class="attributeName">logEffectiveWebXml</code></td><td>
385
        <p>Set to <code>true</code> if you want the effective web.xml used for a
386
        web application to be logged (at INFO level) when the application
387
        starts. The effective web.xml is the result of combining the
388
        application's web.xml with any defaults configured by Tomcat and any
389
        web-fragment.xml files and annotations discovered. If not specified, the
390
        default value of <code>false</code> is used.</p>
391
      </td></tr><tr id="Attributes_Common Attributes_mapperContextRootRedirectEnabled"><td><code class="attributeName">mapperContextRootRedirectEnabled</code></td><td>
392
        <p>If enabled, requests for a web application context root will be
393
        redirected (adding a trailing slash) if necessary by the Mapper rather
394
        than the default Servlet. This is more efficient but there are security
395
        side effects. First, the existence of a web application or a directory
396
        may be confirmed even though the user does not have access to that
397
        directory. Secondly, any Valves and/or Filters - including those
398
        providing security functionality - will not have an opportunity to
399
        process the request. If not specified, the default value of
400
        <code>true</code> is used.</p>
401
      </td></tr><tr id="Attributes_Common Attributes_mapperDirectoryRedirectEnabled"><td><code class="attributeName">mapperDirectoryRedirectEnabled</code></td><td>
402
        <p>If enabled, requests for a web application directory will be
403
        redirected (adding a trailing slash) if necessary by the Mapper rather
404
        than the default Servlet. This is more efficient but there are security
405
        side effects. First, the existence of a web application or a directory
406
        may be confirmed even though the user does not have access to that
407
        directory. Secondly, any Valves and/or Filters - including those
408
        providing security functionality - will not have an opportunity to
409
        process the request. If not specified, the default value of
410
        <code>false</code> is used.</p>
411
      </td></tr><tr id="Attributes_Common Attributes_override"><td><code class="attributeName">override</code></td><td>
412
        <p>Set to <code>true</code> to ignore any settings in both the global
413
        or <a href="host.html">Host</a> default contexts.  By default, settings
414
        from a default context will be used but may be overridden by a setting
415
        the same attribute explicitly for the Context.</p>
416
      </td></tr><tr id="Attributes_Common Attributes_parallelAnnotationScanning"><td><code class="attributeName">parallelAnnotationScanning</code></td><td>
417
        <p>When set to <code>true</code> annotation scanning will be performed
418
        using the utility executor. It will allow processing scanning in
419
        parallel which may improve deployment type at the expense of higher
420
        server load. If not specified, the default of <code>false</code> is
421
        used.</p>
422
      </td></tr><tr id="Attributes_Common Attributes_path"><td><code class="attributeName">path</code></td><td>
423
        <p>The <em>context path</em> of this web application, which is
424
        matched against the beginning of each request URI to select the
425
        appropriate web application for processing.  All of the context paths
426
        within a particular <a href="host.html">Host</a> must be unique.
427
        If you specify a context path of an empty string (""), you are
428
        defining the <em>default</em> web application for this Host, which
429
        will process all requests not assigned to other Contexts.</p>
430
        <p>This attribute must only be used when statically defining a Context
431
        in server.xml. In all other circumstances, the path will be inferred
432
        from the filenames used for either the .xml context file or the
433
        <code>docBase</code>.
434
        </p>
435
        <p>Even when statically defining a Context in server.xml, this attribute
436
        must not be set unless either the <code>docBase</code> is not located
437
        under the <a href="host.html">Host</a>'s <code>appBase</code> or
438
        both <code>deployOnStartup</code> and <code>autoDeploy</code> are
439
        <code>false</code>. If this rule is not followed, double deployment is
440
        likely to result.</p>
441
      </td></tr><tr id="Attributes_Common Attributes_preemptiveAuthentication"><td><code class="attributeName">preemptiveAuthentication</code></td><td>
442
        <p>When set to <code>true</code> and the user presents credentials for a
443
        resource that is not protected by a security constraint, if the
444
        authenticator supports preemptive authentication (the standard
445
        authenticators provided with Tomcat do) then the user' credentials
446
        will be processed. If not specified, the default of <code>false</code> is
447
        used.
448
        </p>
449
      </td></tr><tr id="Attributes_Common Attributes_privileged"><td><code class="attributeName">privileged</code></td><td>
450
        <p>Set to <code>true</code> to allow this context to use container
451
        servlets, like the manager servlet. Use of the <code>privileged</code>
452
        attribute will change the context's parent class loader to be the
453
        <em>Server</em> class loader rather than the <em>Shared</em> class
454
        loader. Note that in a default installation, the <em>Common</em> class
455
        loader is used for both the <em>Server</em> and the <em>Shared</em>
456
        class loaders.</p>
457
      </td></tr><tr id="Attributes_Common Attributes_reloadable"><td><code class="attributeName">reloadable</code></td><td>
458
        <p>Set to <code>true</code> if you want Catalina to monitor classes in
459
        <code>/WEB-INF/classes/</code> and <code>/WEB-INF/lib</code> for
460
        changes, and automatically reload the web application if a change
461
        is detected.  This feature is very useful during application
462
        development, but it requires significant runtime overhead and is
463
        not recommended for use on deployed production applications.  That's
464
        why the default setting for this attribute is <i>false</i>.  You
465
        can use the <a href="../manager-howto.html">Manager</a> web
466
        application, however, to trigger reloads of deployed applications
467
        on demand.</p>
468
      </td></tr><tr id="Attributes_Common Attributes_resourceOnlyServlets"><td><code class="attributeName">resourceOnlyServlets</code></td><td>
469
        <p>Comma separated list of Servlet names (as used in
470
        <code>/WEB-INF/web.xml</code>) that expect a resource to be present.
471
        Ensures that welcome files associated with Servlets that expect a
472
        resource to be present (such as the JSP Servlet) are not used when there
473
        is no resource present. This prevents issues caused by the clarification
474
        of welcome file mapping in section 10.10 of the Servlet 3.0
475
        specification. If the
476
        <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code>
477
        <a href="systemprops.html">system property</a> is set to
478
        <code>true</code>, the default value of this attribute will be the empty
479
        string, else the default value will be <code>jsp</code>.</p>
480
      </td></tr><tr id="Attributes_Common Attributes_sendRedirectBody"><td><code class="attributeName">sendRedirectBody</code></td><td>
481
        <p>If <code>true</code>, redirect responses will include a short
482
        response body that includes details of the redirect as recommended by
483
        RFC 2616. This is disabled by default since including a response body
484
        may cause problems for some application component such as compression
485
        filters.</p>
486
      </td></tr><tr id="Attributes_Common Attributes_sessionCookieDomain"><td><code class="attributeName">sessionCookieDomain</code></td><td>
487
        <p>The domain to be used for all session cookies created for this
488
        context. If set, this overrides any domain set by the web application.
489
        If not set, the value specified by the web application, if any, will be
490
        used.</p>
491
      </td></tr><tr id="Attributes_Common Attributes_sessionCookieName"><td><code class="attributeName">sessionCookieName</code></td><td>
492
        <p>The name to be used for all session cookies created for this
493
        context. If set, this overrides any name set by the web application.
494
        If not set, the value specified by the web application, if any, will be
495
        used, or the name <code>JSESSIONID</code> if the web application does
496
        not explicitly set one.</p>
497
      </td></tr><tr id="Attributes_Common Attributes_sessionCookiePath"><td><code class="attributeName">sessionCookiePath</code></td><td>
498
        <p>The path to be used for all session cookies created for this
499
        context. If set, this overrides any path set by the web application.
500
        If not set, the value specified by the web application will be used, or
501
        the context path used if the web application does not explicitly set
502
        one. To configure all web application to use an empty path (this can be
503
        useful for portlet specification implementations) set this attribute to
504
        <code>/</code> in the global <code>CATALINA_BASE/conf/context.xml</code>
505
        file.</p>
506
        <p>Note: Once one web application using
507
        <code>sessionCookiePath="/"</code> obtains a session, all
508
        subsequent sessions for any other web application in the same host also
509
        configured with <code>sessionCookiePath="/"</code> will always
510
        use the same session ID. This holds even if the session is invalidated
511
        and a new one created. This makes session fixation protection more
512
        difficult and requires custom, Tomcat specific code to change the
513
        session ID shared by the multiple applications.</p>
514
      </td></tr><tr id="Attributes_Common Attributes_sessionCookiePathUsesTrailingSlash"><td><code class="attributeName">sessionCookiePathUsesTrailingSlash</code></td><td>
515
        <p>Some browsers, such as Internet Explorer, Safari and Edge, will send
516
        a session cookie for a context with a path of <code>/foo</code> with a
517
        request to <code>/foobar</code> in violation of RFC6265. This could
518
        expose a session ID from an application deployed at <code>/foo</code> to
519
        an application deployed at <code>/foobar</code>. If the application
520
        deployed at <code>/foobar</code> is untrusted, this could create a
521
        security risk. However, it should be noted that RFC 6265, section 8.5
522
        makes clear that path alone should not be view as sufficient to prevent
523
        untrusted applications accessing cookies from other applications. To
524
        mitigate this risk, this attribute may be set to <code>true</code> and
525
        Tomcat will add a trailing slash to the path associated with the session
526
        cookie so, in the above example, the cookie path becomes /foo/. However,
527
        with a cookie path of /foo/, browsers will no longer send the cookie
528
        with a request to /foo. This should not be a problem unless there is a
529
        servlet mapped to /*. In this case this attribute will need to be set to
530
        <code>false</code> to disable this feature. The default value for this
531
        attribute is <code>false</code>.</p>
532
      </td></tr><tr id="Attributes_Common Attributes_swallowAbortedUploads"><td><code class="attributeName">swallowAbortedUploads</code></td><td>
533
        <p>Set to <code>false</code> if Tomcat should <b>not</b> read any
534
        additional request body data for aborted uploads and instead abort the
535
        client connection. This setting is used in the following situations:
536
        </p>
537
        <ul>
538
        <li>Tomcat is automatically processing the request body for parameters
539
            and size of the request body data converted to parameters is larger
540
            than the <code>maxPostSize</code> configured in the connector</li>
541
        <li>a size limit of a MultiPart upload is reached</li>
542
        <li>the servlet sets the response status to 413 (Request Entity Too
543
            Large) </li>
544
        </ul>
545
        <p>
546
        Not reading the additional data will free the request processing thread
547
        more quickly. Unfortunately most HTTP clients will not read the response
548
        if they cannot write the full request.</p>
549
        <p>The default is <code>true</code>, so additional data will be
550
        read.</p>
551
        <p>Note if an error occurs during the request processing that triggers
552
        a 5xx response, any unread request data will always be ignored and the
553
        client connection will be closed once the error response has been
554
        written.</p>
555
      </td></tr><tr id="Attributes_Common Attributes_swallowOutput"><td><code class="attributeName">swallowOutput</code></td><td>
556
        <p>If the value of this flag is <code>true</code>, the bytes output to
557
        System.out and System.err by the web application will be redirected to
558
        the web application logger. If not specified, the default value
559
        of the flag is <code>false</code>.</p>
560
      </td></tr><tr id="Attributes_Common Attributes_tldValidation"><td><code class="attributeName">tldValidation</code></td><td>
561
        <p>If the value of this flag is <code>true</code>, the TLD files
562
        will be XML validated on context startup. If the
563
        <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code>
564
        <a href="systemprops.html">system property</a> is set to
565
        <code>true</code>, the default value of this attribute will be
566
        <code>true</code>, else the default value will be <code>false</code>.
567
        Setting this attribute to <code>true</code> will incur a performance
568
        penalty.</p>
569
      </td></tr><tr id="Attributes_Common Attributes_useBloomFilterForArchives"><td><code class="attributeName">useBloomFilterForArchives</code></td><td>
570
        <p>DEPRECATED: If this is <code>true</code> then a bloom filter will be
571
        used to speed up archive lookups. This can be beneficial to the deployment
572
        speed to web applications that contain very large amount of JARs.</p>
573
        <p>If not specified, the default value of <code>false</code> will be
574
        used.</p>
575
        <p>This value can be overridden by archiveIndexStrategy in
576
        <a href="resources.html">Resources</a></p>
577
      </td></tr><tr id="Attributes_Common Attributes_useHttpOnly"><td><code class="attributeName">useHttpOnly</code></td><td>
578
       <p>Should the HttpOnly flag be set on session cookies to prevent client
579
          side script from accessing the session ID? Defaults to
580
          <code>true</code>.</p>
581
      </td></tr><tr id="Attributes_Common Attributes_useRelativeRedirects"><td><code class="attributeName">useRelativeRedirects</code></td><td>
582
        <p>Controls whether HTTP 1.1 and later location headers generated by a
583
        call to
584
        <code>javax.servlet.http.HttpServletResponse#sendRedirect(String)</code>
585
        will use relative or absolute redirects. Relative redirects are more
586
        efficient but may not work with reverse proxies that change the context
587
        path. It should be noted that it is not recommended to use a reverse
588
        proxy to change the context path because of the multiple issues it
589
        creates. Absolute redirects should work with reverse proxies that change
590
        the context path but may cause issues with the
591
        <code>org.apache.catalina.filters.RemoteIpFilter</code> if the filter is
592
         changing the scheme and/or port. If the
593
        <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code>
594
        <a href="systemprops.html">system property</a> is set to
595
        <code>true</code>, the default value of this attribute will be
596
        <code>false</code>, else the default value will be <code>true</code>.
597
        </p>
598
      </td></tr><tr id="Attributes_Common Attributes_validateClientProvidedNewSessionId"><td><code class="attributeName">validateClientProvidedNewSessionId</code></td><td>
599
        <p>When a client provides the ID for a new session, this attribute
600
        controls whether that ID is validated. The only use case for using a
601
        client provided session ID is to have a common session ID across
602
        multiple web applications. Therefore, any client provided session ID
603
        should already exist in another web application. If this check is
604
        enabled, the client provided session ID will only be used if the session
605
        ID exists in at least one other web application for the current host.
606
        Note that the following additional tests are always applied,
607
        irrespective of this setting:</p>
608
        <ul>
609
          <li>The session ID is provided by a cookie</li>
610
          <li>The session cookie has a path of {@code /}</li>
611
        </ul>
612
        <p>If not specified, the default value of <code>true</code> will be
613
        used.</p>
614
      </td></tr><tr id="Attributes_Common Attributes_wrapperClass"><td><code class="attributeName">wrapperClass</code></td><td>
615
        <p>Java class name of the <code>org.apache.catalina.Wrapper</code>
616
        implementation class that will be used for servlets managed by this
617
        Context.  If not specified, a standard default value will be used.</p>
618
      </td></tr><tr id="Attributes_Common Attributes_xmlBlockExternal"><td><code class="attributeName">xmlBlockExternal</code></td><td>
619
        <p>If the value of this flag is <code>true</code>, the parsing of
620
        <code>web.xml</code>, <code>web-fragment.xml</code>,
621
        <code>tomcat-web.xml</code>, <code>*.tld</code>, <code>*.jspx</code>,
622
        <code>*.tagx</code> and <code>tagPlugins.xml</code> files for this web
623
        application will not permit external entities to be loaded. If not
624
        specified, the default value of <code>true</code> will be used.</p>
625
      </td></tr><tr id="Attributes_Common Attributes_xmlNamespaceAware"><td><code class="attributeName">xmlNamespaceAware</code></td><td>
626
        <p>If the value of this flag is <code>true</code>, the parsing of
627
        <code>web.xml</code>, <code>web-fragment.xml</code> and
628
        <code>tomcat-web.xml</code> files for this web application will be
629
        namespace-aware. Note that <code>*.tld</code>, <code>*.jspx</code> and
630
        <code>*.tagx</code> files are always parsed using a namespace-aware
631
        parser and that the <code>tagPlugins.xml</code> file (if any) is never
632
        parsed using a namespace-aware parser. Note also that if you turn this
633
        flag on, you should probably also turn <code>xmlValidation</code> on. If
634
        the <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code>
635
        <a href="systemprops.html">system property</a> is set to
636
        <code>true</code>, the default value of this attribute will be
637
        <code>true</code>, else the default value will be <code>false</code>.
638
        Setting this attribute to <code>true</code> will incur a performance
639
        penalty.</p>
640
      </td></tr><tr id="Attributes_Common Attributes_xmlValidation"><td><code class="attributeName">xmlValidation</code></td><td>
641
        <p>If the value of this flag is <code>true</code>, the parsing of
642
        <code>web.xml</code>, <code>web-fragment.xml</code> and
643
        <code>tomcat-web.xml</code> files for this web application will use a
644
        validating parser. If the
645
        <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code>
646
        <a href="systemprops.html">system property</a> is set to
647
        <code>true</code>, the default value of this attribute will be
648
        <code>true</code>, else the default value will be <code>false</code>.
649
        Setting this attribute to <code>true</code> will incur a performance
650
        penalty.</p>
651
      </td></tr></table>
652
 
653
  </div></div>
654
 
655
 
656
  <div class="subsection"><h4 id="Standard_Implementation">Standard Implementation</h4><div class="text">
657
 
658
    <p>The standard implementation of <strong>Context</strong> is
659
    <strong>org.apache.catalina.core.StandardContext</strong>.
660
    It supports the following additional attributes (in addition to the
661
    common attributes listed above):</p>
662
 
663
    <table class="defaultTable"><tr><th style="width: 15%;">
664
          Attribute
665
        </th><th style="width: 85%;">
666
          Description
667
        </th></tr><tr id="Attributes_Standard Implementation_addWebinfClassesResources"><td><code class="attributeName">addWebinfClassesResources</code></td><td>
668
        <p>This attribute controls if, in addition to static resources being
669
        served from <code>META-INF/resources</code> inside web application JAR
670
        files, static resources are also served from
671
        <code>WEB-INF/classes/META-INF/resources</code>. This only applies to
672
        web applications with a major version of 3 or higher. Since this is a
673
        proprietary extension to the Servlet 3 specification, it is disabled by
674
        default. To enable this feature, set the attribute to <code>true</code>.
675
        </p>
676
      </td></tr><tr id="Attributes_Standard Implementation_antiResourceLocking"><td><code class="attributeName">antiResourceLocking</code></td><td>
677
        <p>If <code>true</code>, Tomcat will prevent any file locking.
678
        This will significantly impact startup time of applications,
679
        but allows full webapp hot deploy and undeploy on platforms
680
        or configurations where file locking can occur.
681
        If not specified, the default value is <code>false</code>.</p>
682
 
683
        <p>Please note that setting this to <code>true</code> has some side
684
        effects, including the disabling of JSP reloading in a running server:
685
        see <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=37668">
686
        Bugzilla 37668</a>.</p>
687
 
688
        <p>Please note that setting this flag to <code>true</code> in
689
        applications that are outside the <code>appBase</code> for the Host (the
690
        <code>webapps</code> directory by default) will cause the application to
691
        be <strong>deleted</strong> on Tomcat shutdown.  You probably don't want
692
        to do this, so think twice before setting antiResourceLocking=true on a
693
        webapp that's outside the <code>appBase</code> for its Host.</p>
694
      </td></tr><tr id="Attributes_Standard Implementation_clearReferencesHttpClientKeepAliveThread"><td><code class="attributeName">clearReferencesHttpClientKeepAliveThread</code></td><td>
695
        <p>If <code>true</code> and an <code>sun.net.www.http.HttpClient</code>
696
        keep-alive timer thread has been started by this web application and is
697
        still running, Tomcat will change the context class loader for that
698
        thread from the web application class loader to the parent of the web
699
        application class loader to prevent a memory leak. Note that the
700
        keep-alive timer thread will stop on its own once the keep-alives all
701
        expire however, on a busy system that might not happen for some time. If
702
        not specified, the default value of <code>true</code> will be used.</p>
703
      </td></tr><tr id="Attributes_Standard Implementation_clearReferencesObjectStreamClassCaches"><td><code class="attributeName">clearReferencesObjectStreamClassCaches</code></td><td>
704
        <p>If <code>true</code>, when the web application is stopped Tomcat
705
        looks for <code>SoftReference</code>s to classes loaded by the web
706
        application in the <code>ObjectStreamClass</code> class used for
707
        serialization and clears any <code>SoftReference</code>s it finds. This
708
        feature uses reflection to identify the <code>SoftReference</code>s and
709
        therefore requires that the command line option
710
        <code>-XaddExports:java.base/java.io=ALL-UNNAMED</code> is set
711
        when running on Java 9 and above. If not specified, the default value of
712
        <code>true</code> will be used.</p>
713
        <p>The memory leak associated with <code>ObjectStreamClass</code> has
714
        been fixed in Java 19 onwards, Java 17.0.4 onwards and Java 11.0.16
715
        onwards. The check will be disabled when running on a version
716
        of Java that contains the fix.</p>
717
      </td></tr><tr id="Attributes_Standard Implementation_clearReferencesRmiTargets"><td><code class="attributeName">clearReferencesRmiTargets</code></td><td>
718
        <p>If <code>true</code>, Tomcat looks for memory leaks associated with
719
        RMI Targets and clears any it finds. This feature uses reflection to
720
        identify the leaks and therefore requires that the command line option
721
        <code>-XaddExports:java.rmi/sun.rmi.transport=ALL-UNNAMED</code> is set
722
        when running on Java 9 and above. Applications without memory leaks
723
        should operate correctly with this attribute set to <code>false</code>.
724
        If not specified, the default value of <code>true</code> will be used.</p>
725
      </td></tr><tr id="Attributes_Standard Implementation_clearReferencesStopThreads"><td><code class="attributeName">clearReferencesStopThreads</code></td><td>
726
        <p>If <code>true</code>, Tomcat attempts to terminate threads that have
727
        been started by the web application. Stopping threads is performed via
728
        the deprecated (for good reason) <code>Thread.stop()</code> method and
729
        is likely to result in instability. As such, enabling this should be
730
        viewed as an option of last resort in a development environment and is
731
        not recommended in a production environment. If not specified, the
732
        default value of <code>false</code> will be used. If this feature is
733
        enabled, web applications may take up to two seconds longer to stop as
734
        executor threads are given up to two seconds to stop gracefully before
735
        <code>Thread.stop()</code> is called on any remaining threads.</p>
736
      </td></tr><tr id="Attributes_Standard Implementation_clearReferencesStopTimerThreads"><td><code class="attributeName">clearReferencesStopTimerThreads</code></td><td>
737
        <p>If <code>true</code>, Tomcat attempts to terminate
738
        <code>java.util.Timer</code> threads that have been started by the web
739
        application. Unlike standard threads, timer threads can be stopped
740
        safely although there may still be side-effects for the application. If
741
        not specified, the default value of <code>false</code> will be used.</p>
742
      </td></tr><tr id="Attributes_Standard Implementation_clearReferencesThreadLocals"><td><code class="attributeName">clearReferencesThreadLocals</code></td><td>
743
        <p>If <code>true</code>, Tomcat attempts to clear
744
        <code>java.lang.ThreadLocal</code> variables that have been populated
745
        with classes loaded by the web application. If not specified, the
746
        default value of <code>true</code> will be used.</p>
747
      </td></tr><tr id="Attributes_Standard Implementation_copyXML"><td><code class="attributeName">copyXML</code></td><td>
748
        <p>Set to <code>true</code> if you want a context XML descriptor
749
        embedded inside the application (located at
750
        <code>/META-INF/context.xml</code>) to be copied to the owning
751
        <a href="host.html">Host</a>'s <code>xmlBase</code> when the application
752
        is deployed. On subsequent starts, the copied context XML descriptor
753
        will be used in preference to any context XML descriptor embedded inside
754
        the application even if the descriptor embedded inside the application
755
        is more recent. The default is <code>false</code>. Note if
756
        the <strong>deployXML</strong> attribute of the owning
757
        <a href="host.html">Host</a> is <code>false</code> or if the
758
        <strong>copyXML</strong> attribute of the owning
759
        <a href="host.html">Host</a> is <code>true</code>, this attribute will
760
        have no effect.</p>
761
      </td></tr><tr id="Attributes_Standard Implementation_jndiExceptionOnFailedWrite"><td><code class="attributeName">jndiExceptionOnFailedWrite</code></td><td>
762
        <p>If <code>true</code>, any attempt by an application to modify the
763
        provided JNDI context with a call to bind(), unbind(),
764
        createSubContext(), destroySubContext() or close() will trigger a
765
        <code>javax.naming.OperationNotSupportedException</code> as required by
766
        section EE.5.3.4 of the Java EE specification. This exception can be
767
        disabled by setting this attribute to <code>false</code> in which case
768
        any calls to modify the JNDI context will return <b>without</b> making
769
        any changes and methods that return values will return
770
        <code>null</code>. If not specified, the specification compliant default
771
        of <code>true</code> will be used.</p>
772
      </td></tr><tr id="Attributes_Standard Implementation_notFoundClassResourceCacheSize"><td><code class="attributeName">notFoundClassResourceCacheSize</code></td><td>
773
        <p>Class resources are not cached by the standard resources
774
        implementation since they are loaded on first use and then the resource
775
        is then no longer required. It does help, however, to cache classes that
776
        are not found as in some scenarios the same class will be searched for
777
        many times and the greater the number of JARs/classes, the longer that
778
        search will take. An LRU cache is used and this attribute controls the
779
        size of that cache. A value of less than 1 disables the cache. If not
780
        specified, the default value of 1000 will be used.</p>
781
      </td></tr><tr id="Attributes_Standard Implementation_renewThreadsWhenStoppingContext"><td><code class="attributeName">renewThreadsWhenStoppingContext</code></td><td>
782
        <p>If <code>true</code>, when this context is stopped, Tomcat renews all
783
        the threads from the thread pool that was used to serve this context.
784
        This also requires that the
785
        <code>ThreadLocalLeakPreventionListener</code> be configured in
786
        <code>server.xml</code> and that the <code>threadRenewalDelay</code>
787
        property of the <code>Executor</code> be &gt;=0. If not specified, the
788
        default value of <code>true</code> will be used.</p>
789
      </td></tr><tr id="Attributes_Standard Implementation_skipMemoryLeakChecksOnJvmShutdown"><td><code class="attributeName">skipMemoryLeakChecksOnJvmShutdown</code></td><td>
790
        <p>If <code>true</code>, Tomcat will not perform the usual memory leak
791
        checks when the web application is stopped if that web application is
792
        stopped as part of a JVM shutdown. If not specified, the default value
793
        of <code>false</code> will be used.</p>
794
      </td></tr><tr id="Attributes_Standard Implementation_unloadDelay"><td><code class="attributeName">unloadDelay</code></td><td>
795
        <p>Number of ms that the container will wait for servlets to unload.
796
        If not specified, the default value is <code>2000</code> ms.</p>
797
      </td></tr><tr id="Attributes_Standard Implementation_unpackWAR"><td><code class="attributeName">unpackWAR</code></td><td>
798
        <p>If <code>false</code>, the <strong>unpackWARs</strong> attribute of
799
        the owning <a href="host.html">Host</a> will be overridden and the WAR
800
        file will not be unpacked. If <code>true</code>, the value of the owning
801
        <a href="host.html">Host</a>'s <strong>unpackWARs</strong>
802
        attribute will determine if the WAR is unpacked. If not specified, the
803
        default value is <code>true</code>.</p>
804
      </td></tr><tr id="Attributes_Standard Implementation_useNaming"><td><code class="attributeName">useNaming</code></td><td>
805
        <p>Set to <code>true</code> (the default) to have Catalina enable a
806
        JNDI <code>InitialContext</code> for this web application that is
807
        compatible with Java2 Enterprise Edition (J2EE) platform
808
        conventions.</p>
809
      </td></tr><tr id="Attributes_Standard Implementation_workDir"><td><code class="attributeName">workDir</code></td><td>
810
        <p>Pathname to a scratch directory to be provided by this Context
811
        for temporary read-write use by servlets within the associated web
812
        application.  This directory will be made visible to servlets in the
813
        web application by a servlet context attribute (of type
814
        <code>java.io.File</code>) named
815
        <code>javax.servlet.context.tempdir</code> as described in the
816
        Servlet Specification.  If not specified, a suitable directory
817
        underneath <code>$CATALINA_BASE/work</code> will be provided.</p>
818
      </td></tr></table>
819
 
820
  </div></div>
821
 
822
 
823
</div><h3 id="Nested_Components">Nested Components</h3><div class="text">
824
 
825
  <p>You can nest at most one instance of the following utility components
826
  by nesting a corresponding element inside your <strong>Context</strong>
827
  element:</p>
828
  <ul>
829
  <li><a href="cookie-processor.html"><strong>Cookie Processor</strong></a> -
830
      Configure parsing and generation of HTTP cookie headers.</li>
831
  <li><a href="loader.html"><strong>Loader</strong></a> -
832
      Configure the web application class loader that will be used to load
833
      servlet and bean classes for this web application.  Normally, the
834
      default configuration of the class loader will be sufficient.</li>
835
  <li><a href="manager.html"><strong>Manager</strong></a> -
836
      Configure the session manager that will be used to create, destroy,
837
      and persist HTTP sessions for this web application.  Normally, the
838
      default configuration of the session manager will be sufficient.</li>
839
  <li><a href="realm.html"><strong>Realm</strong></a> -
840
      Configure a realm that will allow its
841
      database of users, and their associated roles, to be utilized solely
842
      for this particular web application.  If not specified, this web
843
      application will utilize the Realm associated with the owning
844
      <a href="host.html">Host</a> or <a href="engine.html">Engine</a>.</li>
845
  <li><a href="resources.html"><strong>Resources</strong></a> -
846
      Configure the resource manager that will be used to access the static
847
      resources associated with this web application.  Normally, the
848
      default configuration of the resource manager will be sufficient.</li>
849
  <li><strong>WatchedResource</strong> - The auto deployer will monitor the
850
      specified static resource of the web application for updates, and will
851
      reload the web application if it is updated. The content of this element
852
      must be a string.</li>
853
  <li><a href="jar-scanner.html"><strong>JarScanner</strong></a> -
854
      Configure the Jar Scanner that will be used to scan the web application
855
      for JAR files and directories of class files. It is typically used during
856
      web application start to identify configuration files such as TLDs o
857
      web-fragment.xml files that must be processed as part of the web
858
      application initialisation.  Normally, the default Jar Scanner
859
      configuration will be sufficient.</li>
860
  </ul>
861
 
862
</div><h3 id="Special_Features">Special Features</h3><div class="text">
863
 
864
 
865
  <div class="subsection"><h4 id="Logging">Logging</h4><div class="text">
866
 
867
    <p>A context is associated with the
868
       <code>org.apache.catalina.core.ContainerBase.[enginename].[hostname].[path]</code>
869
       log category.  Note that the brackets are actually part of the name, don't omit them.</p>
870
 
871
  </div></div>
872
 
873
 
874
  <div class="subsection"><h4 id="Access_Logs">Access Logs</h4><div class="text">
875
 
876
    <p>When you run a web server, one of the output files normally generated
877
    is an <em>access log</em>, which generates one line of information for
878
    each request processed by the server, in a standard format.  Catalina
879
    includes an optional <a href="valve.html">Valve</a> implementation that
880
    can create access logs in the same standard format created by web servers,
881
    or in any number of custom formats.</p>
882
 
883
    <p>You can ask Catalina to create an access log for all requests
884
    processed by an <a href="engine.html">Engine</a>,
885
    <a href="host.html">Host</a>, or <a href="context.html">Context</a>
886
    by nesting a <a href="valve.html">Valve</a> element like this:</p>
887
 
888
<div class="codeBox"><pre><code>&lt;Context&gt;
889
  ...
890
  &lt;Valve className="org.apache.catalina.valves.AccessLogValve"
891
         prefix="localhost_access_log" suffix=".txt"
892
         pattern="common"/&gt;
893
  ...
894
&lt;/Context&gt;</code></pre></div>
895
 
896
    <p>See <a href="valve.html#Access_Logging">Access Logging Valves</a>
897
    for more information on the configuration attributes that are
898
    supported.</p>
899
 
900
  </div></div>
901
 
902
 
903
  <div class="subsection"><h4 id="Automatic_Context_Configuration">Automatic Context Configuration</h4><div class="text">
904
 
905
    <p>If you use the standard <strong>Context</strong> implementation,
906
    the following configuration steps occur automatically when Catalina
907
    is started, or whenever this web application is reloaded.  No special
908
    configuration is required to enable this feature.</p>
909
 
910
    <ul>
911
    <li>If you have not declared your own <a href="loader.html">Loader</a>
912
       element, a standard web application class loader will be configured.
913
       </li>
914
    <li>If you have not declared your own <a href="manager.html">Manager</a>
915
        element, a standard session manager will be configured.</li>
916
    <li>If you have not declared your own <a href="resources.html">Resources</a>
917
        element, a standard resources manager will be configured.</li>
918
    <li>The web application properties listed in <code>conf/web.xml</code>
919
        will be processed as defaults for this web application.  This is used
920
        to establish default mappings (such as mapping the <code>*.jsp</code>
921
        extension to the corresponding JSP servlet), and other standard
922
        features that apply to all web applications.</li>
923
    <li>The web application properties listed in the
924
        <code>/WEB-INF/tomcat-web.xml</code> resource for this web application
925
        will be processed (if this resource exists), taking precedence over the
926
        defaults.</li>
927
    <li>The web application properties listed in the
928
        <code>/WEB-INF/web.xml</code> resource for this web application
929
        will be processed (if this resource exists).</li>
930
    <li>If your web application has specified security constraints that might
931
        require user authentication, an appropriate Authenticator that
932
        implements the login method you have selected will be configured.</li>
933
    </ul>
934
 
935
  </div></div>
936
 
937
 
938
  <div class="subsection"><h4 id="Context_Parameters">Context Parameters</h4><div class="text">
939
 
940
    <p>You can configure named values that will be made visible to the
941
    web application as servlet context initialization parameters by nesting
942
    <code>&lt;Parameter&gt;</code> elements inside this element.  For
943
    example, you can create an initialization parameter like this:</p>
944
<div class="codeBox"><pre><code>&lt;Context&gt;
945
  ...
946
  &lt;Parameter name="companyName" value="My Company, Incorporated"
947
         override="false"/&gt;
948
  ...
949
&lt;/Context&gt;</code></pre></div>
950
 
951
    <p>This is equivalent to the inclusion of the following element in the
952
    web application deployment descriptor (<code>/WEB-INF/web.xml</code>):
953
    </p>
954
<div class="codeBox"><pre><code>&lt;context-param&gt;
955
  &lt;param-name&gt;companyName&lt;/param-name&gt;
956
  &lt;param-value&gt;My Company, Incorporated&lt;/param-value&gt;
957
&lt;/context-param&gt;</code></pre></div>
958
    <p>but does <em>not</em> require modification of the deployment descriptor
959
    to customize this value.</p>
960
 
961
    <p>The valid attributes for a <code>&lt;Parameter&gt;</code> element
962
    are as follows:</p>
963
 
964
    <table class="defaultTable"><tr><th style="width: 15%;">
965
          Attribute
966
        </th><th style="width: 85%;">
967
          Description
968
        </th></tr><tr id="Special Features_Context Parameters_description"><td><code class="attributeName">description</code></td><td>
969
        <p>Optional, human-readable description of this context
970
        initialization parameter.</p>
971
      </td></tr><tr id="Special Features_Context Parameters_name"><td><strong><code class="attributeName">name</code></strong></td><td>
972
        <p>The name of the context initialization parameter to be created.</p>
973
      </td></tr><tr id="Special Features_Context Parameters_override"><td><code class="attributeName">override</code></td><td>
974
        <p>Set this to <code>false</code> if you do <strong>not</strong> want
975
        a <code>&lt;context-param&gt;</code> for the same parameter name,
976
        found in the web application deployment descriptor, to override the
977
        value specified here.  By default, overrides are allowed.</p>
978
      </td></tr><tr id="Special Features_Context Parameters_value"><td><strong><code class="attributeName">value</code></strong></td><td>
979
        <p>The parameter value that will be presented to the application
980
        when requested by calling
981
        <code>ServletContext.getInitParameter()</code>.</p>
982
      </td></tr></table>
983
 
984
  </div></div>
985
 
986
 
987
  <div class="subsection"><h4 id="Environment_Entries">Environment Entries</h4><div class="text">
988
 
989
    <p>You can configure named values that will be made visible to the
990
    web application as environment entry resources, by nesting
991
    <code>&lt;Environment&gt;</code> entries inside this element.  For
992
    example, you can create an environment entry like this:</p>
993
<div class="codeBox"><pre><code>&lt;Context&gt;
994
  ...
995
  &lt;Environment name="maxExemptions" value="10"
996
         type="java.lang.Integer" override="false"/&gt;
997
  ...
998
&lt;/Context&gt;</code></pre></div>
999
 
1000
    <p>This is equivalent to the inclusion of the following element in the
1001
    web application deployment descriptor (<code>/WEB-INF/web.xml</code>):
1002
    </p>
1003
<div class="codeBox"><pre><code>&lt;env-entry&gt;
1004
  &lt;env-entry-name&gt;maxExemptions&lt;/env-entry-name&gt;
1005
  &lt;env-entry-value&gt;10&lt;/env-entry-value&gt;
1006
  &lt;env-entry-type&gt;java.lang.Integer&lt;/env-entry-type&gt;
1007
&lt;/env-entry&gt;</code></pre></div>
1008
    <p>but does <em>not</em> require modification of the deployment descriptor
1009
    to customize this value.</p>
1010
 
1011
    <p>The valid attributes for an <code>&lt;Environment&gt;</code> element
1012
    are as follows:</p>
1013
 
1014
    <table class="defaultTable"><tr><th style="width: 15%;">
1015
          Attribute
1016
        </th><th style="width: 85%;">
1017
          Description
1018
        </th></tr><tr id="Special Features_Environment Entries_description"><td><code class="attributeName">description</code></td><td>
1019
        <p>Optional, human-readable description of this environment entry.</p>
1020
      </td></tr><tr id="Special Features_Environment Entries_name"><td><strong><code class="attributeName">name</code></strong></td><td>
1021
        <p>The name of the environment entry to be created, relative to the
1022
        <code>java:comp/env</code> context.</p>
1023
      </td></tr><tr id="Special Features_Environment Entries_override"><td><code class="attributeName">override</code></td><td>
1024
        <p>Set this to <code>false</code> if you do <strong>not</strong> want
1025
        an <code>&lt;env-entry&gt;</code> for the same environment entry name,
1026
        found in the web application deployment descriptor, to override the
1027
        value specified here.  By default, overrides are allowed.</p>
1028
      </td></tr><tr id="Special Features_Environment Entries_type"><td><strong><code class="attributeName">type</code></strong></td><td>
1029
        <p>The fully qualified Java class name expected by the web application
1030
        for this environment entry.  Must be a legal value for
1031
        <code>&lt;env-entry-type&gt;</code> in the web application deployment
1032
        descriptor.</p>
1033
      </td></tr><tr id="Special Features_Environment Entries_value"><td><strong><code class="attributeName">value</code></strong></td><td>
1034
        <p>The parameter value that will be presented to the application
1035
        when requested from the JNDI context.  This value must be convertible
1036
        to the Java type defined by the <code>type</code> attribute.</p>
1037
      </td></tr></table>
1038
 
1039
  </div></div>
1040
 
1041
 
1042
  <div class="subsection"><h4 id="Lifecycle_Listeners">Lifecycle Listeners</h4><div class="text">
1043
 
1044
    <p>If you have implemented a Java object that needs to know when this
1045
    <strong>Context</strong> is started or stopped, you can declare it by
1046
    nesting a <strong>Listener</strong> element inside this element.  The
1047
    class name you specify must implement the
1048
    <code>org.apache.catalina.LifecycleListener</code> interface, and
1049
    the class must be packaged in a jar and placed in the
1050
    <code>$CATALINA_HOME/lib</code> directory.
1051
    It will be notified about the occurrence of the corresponding
1052
    lifecycle events.  Configuration of such a listener looks like this:</p>
1053
 
1054
<div class="codeBox"><pre><code>&lt;Context&gt;
1055
  ...
1056
  &lt;Listener className="com.mycompany.mypackage.MyListener" ... &gt;
1057
  ...
1058
&lt;/Context&gt;</code></pre></div>
1059
 
1060
    <p>Note that a Listener can have any number of additional properties
1061
    that may be configured from this element.  Attribute names are matched
1062
    to corresponding JavaBean property names using the standard property
1063
    method naming patterns.</p>
1064
 
1065
  </div></div>
1066
 
1067
 
1068
  <div class="subsection"><h4 id="Request_Filters">Request Filters</h4><div class="text">
1069
 
1070
    <p>You can ask Catalina to check the IP address, or host name, on every
1071
    incoming request directed to the surrounding
1072
    <a href="engine.html">Engine</a>, <a href="host.html">Host</a>, or
1073
    <a href="context.html">Context</a> element.  The remote address or name
1074
    will be checked against configured "accept" and/or "deny"
1075
    filters, which are defined using <code>java.util.regex</code> Regular
1076
    Expression syntax.  Requests that come from locations that are
1077
    not accepted will be rejected with an HTTP "Forbidden" error.
1078
    Example filter declarations:</p>
1079
 
1080
<div class="codeBox"><pre><code>&lt;Context&gt;
1081
  ...
1082
  &lt;Valve className="org.apache.catalina.valves.RemoteHostValve"
1083
         allow=".*\.mycompany\.com|www\.yourcompany\.com"/&gt;
1084
  &lt;Valve className="org.apache.catalina.valves.RemoteCIDRValve"
1085
         deny="192.168.1.0/24"/&gt;
1086
  ...
1087
&lt;/Context&gt;</code></pre></div>
1088
 
1089
    <p>See <a href="valve.html#Remote_Address_Filter">Remote Address Filter</a>
1090
    and <a href="valve.html#Remote_Host_Filter">Remote Host Filter</a> for
1091
    more information about the configuration options that are supported.</p>
1092
 
1093
  </div></div>
1094
 
1095
 
1096
  <div class="subsection"><h4 id="Resource_Definitions">Resource Definitions</h4><div class="text">
1097
 
1098
    <p>You can declare the characteristics of the resource
1099
    to be returned for JNDI lookups of <code>&lt;resource-ref&gt;</code> and
1100
    <code>&lt;resource-env-ref&gt;</code> elements in the web application
1101
    deployment descriptor.  You <strong>MUST</strong> also define
1102
    the needed resource parameters as attributes of the <code>Resource</code>
1103
    element, to configure the object factory to be used (if not known to Tomcat
1104
    already), and the properties used to configure that object factory.</p>
1105
 
1106
    <p>For example, you can create a resource definition like this:</p>
1107
<div class="codeBox"><pre><code>&lt;Context&gt;
1108
  ...
1109
  &lt;Resource name="jdbc/EmployeeDB" auth="Container"
1110
            type="javax.sql.DataSource"
1111
     description="Employees Database for HR Applications"/&gt;
1112
  ...
1113
&lt;/Context&gt;</code></pre></div>
1114
 
1115
    <p>This is equivalent to the inclusion of the following element in the
1116
    web application deployment descriptor (<code>/WEB-INF/web.xml</code>):</p>
1117
<div class="codeBox"><pre><code>&lt;resource-ref&gt;
1118
  &lt;description&gt;Employees Database for HR Applications&lt;/description&gt;
1119
  &lt;res-ref-name&gt;jdbc/EmployeeDB&lt;/res-ref-name&gt;
1120
  &lt;res-ref-type&gt;javax.sql.DataSource&lt;/res-ref-type&gt;
1121
  &lt;res-auth&gt;Container&lt;/res-auth&gt;
1122
&lt;/resource-ref&gt;</code></pre></div>
1123
 
1124
    <p>but does <em>not</em> require modification of the deployment
1125
    descriptor to customize this value.</p>
1126
 
1127
    <p>The valid attributes for a <code>&lt;Resource&gt;</code> element
1128
    are as follows:</p>
1129
 
1130
    <table class="defaultTable"><tr><th style="width: 15%;">
1131
          Attribute
1132
        </th><th style="width: 85%;">
1133
          Description
1134
        </th></tr><tr id="Special Features_Resource Definitions_auth"><td><code class="attributeName">auth</code></td><td>
1135
        <p>Specify whether the web Application code signs on to the
1136
        corresponding resource manager programmatically, or whether the
1137
        Container will sign on to the resource manager on behalf of the
1138
        application.  The value of this attribute must be
1139
        <code>Application</code> or <code>Container</code>.  This
1140
        attribute is <strong>required</strong> if the web application
1141
        will use a <code>&lt;resource-ref&gt;</code> element in the web
1142
        application deployment descriptor, but is optional if the
1143
        application uses a <code>&lt;resource-env-ref&gt;</code> instead.</p>
1144
      </td></tr><tr id="Special Features_Resource Definitions_closeMethod"><td><code class="attributeName">closeMethod</code></td><td>
1145
        <p>Name of the zero-argument method to call on a singleton resource when
1146
        it is no longer required. This is intended to speed up clean-up of
1147
        resources that would otherwise happen as part of garbage collection.
1148
        This attribute is ignored if the <code>singleton</code> attribute is
1149
        <code>false</code>.</p>
1150
        <p>For <code>javax.sql.DataSource</code> and
1151
        <code>javax.sql.XADataSource</code> resources that implement
1152
        <code>AutoCloseable</code> such as Apache Commons DBCP 2 and the default
1153
        Apache Tomcat connection pool, this attribute is defaults to
1154
        <code>close</code>. This may be disabled by setting the attribute to the
1155
        empty string. For all other resource types no default is defined and no
1156
        close method will be called by default.</p>
1157
      </td></tr><tr id="Special Features_Resource Definitions_description"><td><code class="attributeName">description</code></td><td>
1158
        <p>Optional, human-readable description of this resource.</p>
1159
      </td></tr><tr id="Special Features_Resource Definitions_name"><td><strong><code class="attributeName">name</code></strong></td><td>
1160
        <p>The name of the resource to be created, relative to the
1161
        <code>java:comp/env</code> context.</p>
1162
      </td></tr><tr id="Special Features_Resource Definitions_scope"><td><code class="attributeName">scope</code></td><td>
1163
        <p>Specify whether connections obtained through this resource
1164
        manager can be shared.  The value of this attribute must be
1165
        <code>Shareable</code> or <code>Unshareable</code>.  By default,
1166
        connections are assumed to be shareable.</p>
1167
      </td></tr><tr id="Special Features_Resource Definitions_singleton"><td><code class="attributeName">singleton</code></td><td>
1168
        <p>Specify whether this resource definition is for a singleton resource,
1169
        i.e. one where there is only a single instance of the resource. If this
1170
        attribute is <code>true</code>, multiple JNDI lookups for this resource
1171
        will return the same object. If this attribute is <code>false</code>,
1172
        multiple JNDI lookups for this resource will return different objects.
1173
        This attribute must be <code>true</code> for
1174
        <code>javax.sql.DataSource</code> resources to enable JMX registration
1175
        of the DataSource. The value of this attribute must be <code>true</code>
1176
        or <code>false</code>. By default, this attribute is <code>true</code>.
1177
        </p>
1178
      </td></tr><tr id="Special Features_Resource Definitions_type"><td><strong><code class="attributeName">type</code></strong></td><td>
1179
        <p>The fully qualified Java class name expected by the web
1180
        application when it performs a lookup for this resource.</p>
1181
      </td></tr></table>
1182
 
1183
 
1184
  </div></div>
1185
 
1186
 
1187
  <div class="subsection"><h4 id="Resource_Links">Resource Links</h4><div class="text">
1188
 
1189
     <p>This element is used to create a link to a global JNDI resource. Doing
1190
     a JNDI lookup on the link name will then return the linked global
1191
     resource.</p>
1192
 
1193
    <p>For example, you can create a resource link like this:</p>
1194
<div class="codeBox"><pre><code>&lt;Context&gt;
1195
  ...
1196
  &lt;ResourceLink name="linkToGlobalResource"
1197
            global="simpleValue"
1198
            type="java.lang.Integer"
1199
  ...
1200
&lt;/Context&gt;</code></pre></div>
1201
 
1202
    <p>The valid attributes for a <code>&lt;ResourceLink&gt;</code> element
1203
    are as follows:</p>
1204
 
1205
    <table class="defaultTable"><tr><th style="width: 15%;">
1206
          Attribute
1207
        </th><th style="width: 85%;">
1208
          Description
1209
        </th></tr><tr id="Special Features_Resource Links_global"><td><strong><code class="attributeName">global</code></strong></td><td>
1210
        <p>The name of the linked global resource in the
1211
        global JNDI context.</p>
1212
      </td></tr><tr id="Special Features_Resource Links_name"><td><strong><code class="attributeName">name</code></strong></td><td>
1213
        <p>The name of the resource link to be created, relative to the
1214
        <code>java:comp/env</code> context.</p>
1215
      </td></tr><tr id="Special Features_Resource Links_type"><td><strong><code class="attributeName">type</code></strong></td><td>
1216
        <p>The fully qualified Java class name expected by the web
1217
        application when it performs a lookup for this resource link.</p>
1218
      </td></tr><tr id="Special Features_Resource Links_factory"><td><code class="attributeName">factory</code></td><td>
1219
        <p>The fully qualified Java class name for the class creating these objects.
1220
        This class should implement the <code>javax.naming.spi.ObjectFactory</code> interface.</p>
1221
      </td></tr></table>
1222
 
1223
    <p>When the attribute <code>factory="org.apache.naming.factory.DataSourceLinkFactory"</code> the resource link can be used with
1224
       two additional attributes to allow a shared data source to be used with different credentials.
1225
       When these two additional attributes are used in combination with the <code>javax.sql.DataSource</code>
1226
       type, different contexts can share a global data source with different credentials.
1227
       Under the hood, what happens is that a call to <a href="https://docs.oracle.com/javase/8/docs/api/javax/sql/DataSource.html#getConnection()"><code>getConnection()</code></a>
1228
       is simply translated to a call <a href="https://docs.oracle.com/javase/8/docs/api/javax/sql/DataSource.html#getConnection(java.lang.String,%20java.lang.String)">
1229
       <code>getConnection(username, password)</code></a> on the global data source. This is an easy way to get code to be transparent to what schemas are being used,
1230
       yet be able to control connections (or pools) in the global configuration.
1231
    </p>
1232
    <table class="defaultTable"><tr><th style="width: 15%;">
1233
          Attribute
1234
        </th><th style="width: 85%;">
1235
          Description
1236
        </th></tr><tr id="Special Features_Resource Links_username"><td><code class="attributeName">username</code></td><td>
1237
        <p><code>username</code> value for the <code>getConnection(username, password)</code>
1238
           call on the linked global DataSource.
1239
        </p>
1240
      </td></tr><tr id="Special Features_Resource Links_password"><td><code class="attributeName">password</code></td><td>
1241
        <p><code>password</code> value for the <code>getConnection(username, password)</code>
1242
           call on the linked global DataSource.
1243
        </p>
1244
      </td></tr></table>
1245
    <p>Shared Data Source Example:</p>
1246
    <p><strong>Warning:</strong> This feature works only if the global DataSource
1247
supports <code>getConnection(username, password)</code> method.
1248
<a href="https://commons.apache.org/dbcp/">Apache Commons DBCP 2</a> pool that
1249
Tomcat uses by default does not support it. See its Javadoc for
1250
<code>BasicDataSource</code> class.
1251
<a href="../jdbc-pool.html">Apache Tomcat JDBC pool</a> does support it,
1252
but by default this support is disabled and can be enabled by
1253
<code>alternateUsernameAllowed</code> attribute. See its documentation
1254
for details.</p>
1255
<div class="codeBox"><pre><code>&lt;GlobalNamingResources&gt;
1256
  ...
1257
  &lt;Resource name="sharedDataSource"
1258
            global="sharedDataSource"
1259
            type="javax.sql.DataSource"
1260
            factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
1261
            alternateUsernameAllowed="true"
1262
            username="bar"
1263
            password="barpass"
1264
            ...
1265
  ...
1266
&lt;/GlobalNamingResources&gt;
1267
 
1268
&lt;Context path="/foo"...&gt;
1269
  ...
1270
  &lt;ResourceLink
1271
            name="appDataSource"
1272
            global="sharedDataSource"
1273
            type="javax.sql.DataSource"
1274
            factory="org.apache.naming.factory.DataSourceLinkFactory"
1275
            username="foo"
1276
            password="foopass"
1277
  ...
1278
&lt;/Context&gt;
1279
&lt;Context path="/bar"...&gt;
1280
  ...
1281
  &lt;ResourceLink
1282
            name="appDataSource"
1283
            global="sharedDataSource"
1284
            type="javax.sql.DataSource"
1285
  ...
1286
&lt;/Context&gt;</code></pre></div>
1287
    <p>When a request for <code>getConnection()</code> is made in the
1288
       <code>/foo</code> context, the request is translated into
1289
       <code>getConnection("foo","foopass")</code>,
1290
       while a request in the <code>/bar</code> gets passed straight through.</p>
1291
  </div></div>
1292
 
1293
  <div class="subsection"><h4 id="Transaction">Transaction</h4><div class="text">
1294
 
1295
    <p>You can declare the characteristics of the UserTransaction
1296
    to be returned for JNDI lookup for <code>java:comp/UserTransaction</code>.
1297
    You <strong>MUST</strong> define an object factory class to instantiate
1298
    this object as well as the needed resource parameters as attributes of the
1299
    <code>Transaction</code>
1300
    element, and the properties used to configure that object factory.</p>
1301
 
1302
    <p>The valid attributes for the <code>&lt;Transaction&gt;</code> element
1303
    are as follows:</p>
1304
 
1305
    <table class="defaultTable"><tr><th style="width: 15%;">
1306
          Attribute
1307
        </th><th style="width: 85%;">
1308
          Description
1309
        </th></tr><tr id="Special Features_Transaction_factory"><td><strong><code class="attributeName">factory</code></strong></td><td>
1310
        <p>The class name for the JNDI object factory.</p>
1311
      </td></tr></table>
1312
 
1313
  </div></div>
1314
 
1315
</div></div></div></div></div><footer><div id="footer">
1316
    Copyright &copy; 1999-2025, The Apache Software Foundation
1317
    <br>
1318
    Apache Tomcat, Tomcat, Apache, the Apache Tomcat logo and the Apache logo
1319
    are either registered trademarks or trademarks of the Apache Software
1320
    Foundation.
1321
    </div></footer></div></body></html>