原文:http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Definitionshtml
The Context Container(Context容器)java
Introduction(介紹)web
The description below uses the variable name $CATALINA_BASE to refer the base directory against which most relative paths are resolved. If you have not configured Tomcat for multiple instances by setting a CATALINA_BASE directory, then $CATALINA_BASE will be set to the value of $CATALINA_HOME, the directory into which you have installed Tomcat.正則表達式
[下文的描述中,大多數的相對路徑都以$CATALINA_BASE爲基準,若是你沒有經過設置CATALINA_BASE目錄來配置多個Tomcat實例,則$CATALINA_BASE的值就與Tomcat的安裝目錄$CATALINA_HOME相同。]sql
The Context element represents a web application, which is run within a particular virtual host. Each web application is based on a Web Application Archive (WAR) file, or a corresponding directory containing the corresponding unpacked contents, as described in the Servlet Specification (version 2.2 or later). For more information about web application archives, you can download the Servlet Specification, and review the Tomcat Application Developer's Guide.數據庫
[Context元素表明一個web應用,運行在某個特定的虛擬主機上。如Servlet Sepcification2.2或之後版本中描述的那樣,每一個web應用都是基於一個Web Application Archive(WAR)文件,或者一個包含有WAR文件解壓後的內容的目錄。有關Web Application Archive的更多信息,能夠參考Servlet Specification和Tomcat應用程序開發者指南。]apache
The web application used to process each HTTP request is selected by Catalina based on matching the longest possible prefix of the Request URI against the context path of each defined Context. Once selected, that Context will select an appropriate servlet to process the incoming request, according to the servlet mappings defined by the web application deployment.tomcat
[經過將請求URI的最長可能前綴與每一個Context的context路徑進行匹配,Catalina選擇相應的web應用來處理HTTP請求。一旦選定,則Context會根據web application deployment(譯者注:web application deployment即/WEB-INF/web.xml文件)中定義的servlet映射,選擇一個正確的serlvet來處理進來的請求。]安全
You may define as many Context elements as you wish. Each such Context MUST have a unique context name within a virtual host. The context path does not need to be unique (see parallel deployment below). In addition, a Context must be present with a context path equal to a zero-length string. This Context becomes the default web application for this virtual host, and is used to process all requests that do not match any other Context's context path.服務器
[你能夠在一個Host元素中嵌套定義任意多的Context元素。Context的context路徑能夠相同(請看下面的並行部署)。另外,你必須定義一個context路徑長度爲0的Context,這個Context會成爲該虛擬主機的默認web應用,用來處理那些不能匹配任何Context的context路徑的請求。]
Parallel deployment(並行部署)
You may deploy multiple versions of a web application with the same context path at the same time. The rules used to match requests to a context version are as follows:
[你能夠同時使用相同的context路徑部署多個版本的web應用。選擇哪一個context版本對請求進行響應呢?規則以下:]
If no session information is present in the request, use the latest version.
If session information is present in the request, check the session manager of each version for a matching session and if one is found, use that version.
If session information is present in the request but no matching session can be found, use the latest version.
[若是請求中不包含任何session信息,則使用最新的版本。
若是請求中包含session信息,則檢查每一個版本的session管理器(session manager),若是找到與請求中包含的session相匹配版本,則使用該版本。
若是請求中包含session信息,則檢查每一個版本的session管理器(session manager),若是沒有找到與請求中包含的session相匹配版本,則使用最新的版本。]
The Host may be configured (via the undeployOldVersions) to remove old versions deployed in this way once they are no longer in use.
[一旦一個版本再也不被使用,能夠經過配置Host元素(經過Host元素中的undeployOldVersions屬性)來移除舊的版本。]
Naming(命名)
When autoDeploy or deployOnStartup operations are performed by a Host, the name and context path of the web application are derived from the name(s) of the file(s) that define(s) the web application. Consequently, the context path may not be defined in a META-INF/context.xml embedded in the application and there is a close relationship between the context name, context path, context version and the base file name (the name minus any .war or .xml extension) of the file.
[當<Host>元素中使用了autoDeploy或者deployOnStartup屬性時,web應用的名稱和context路徑是從定義該web應用的文件名中讀取出來的。所以,context路徑可能沒有定義在應用中的META-INF/context.xml文件中。另外,context名稱、context路徑、context版本、以及基本文件名稱(base file name,即定義了該web應用的文件名去掉.war或.xml後綴名餘下的部分)之間有密切的聯繫。]
If no version is specified then the context name is always the same as the context path. If the context path is the empty string them the base name will be ROOT (always in upper case) otherwise the base name will be the context path with the leading '/' removed and any remaining '/' characters replaced with '#'.
[若是沒有指定版本號,則context的名稱和context的路徑老是同樣的。若是context的路徑是空字符串,則基名(base name)是ROOT(老是大寫),不然,基名將是去掉context路徑中的第一個'/'字符,並將餘下的全部'/'字符替換成'#'獲得的名稱。]
If a version is specified then the context path remains unchanged and both the context name and the base name have the string '##' appended to them followed by the version identifier.
[若是指定了版本號,則context的名稱和基名都是在沒有指定版本號時獲得的名稱後面追加'##'以及版本號所獲得名稱。]
Some examples of these naming conventions are given below.
[下面給出了這些命名規範的一些例子。]
The version component is treated as a String both for performance reasons and to allow flexibility in versioning schemes. String comparisons are used to determine version order. If version is not specified, it is treated as the empty string. Therefore, foo.war will be treated as an earlier version than foo##11.war and foo##11.war will be treated as an earlier version than foo##2.war. If using a purely numerical versioning scheme it is recommended that zero padding is used so that foo##002.war is treated as an earlier version than foo##011.war.
[不管是從性能因素,仍是從版本管理方案的靈活性來看,版本組件都被視爲字符串(String)。版本的順序是根據字符串的比較來決定的,若是沒有指定版本,則該版本被視爲空字符串。所以,foo.war的版本早於foo##11.war的版本,foo#11.war的版本早於foo##2.war的版本。若是使用數字形式的版本管理方案,則建議使用填充零,這樣的話,foo##002.war的版本早於foo##011.war的版本。]
If you want to deploy a WAR file or a directory using a context path that is not related to the base file name then one of the following options must be used to prevent double-deployment:
[若是想要使用context路徑,該context路徑與文件基本名不關聯,來部署一個WAR文件或者目錄,那麼能夠採起如下建議來避免二次部署:]
Disable autoDeploy and deployOnStartup and define all Contexts in server.xml
Locate the WAR and/or directory outside of the Host's appBase and use a context.xml file with a docBase attribute to define it.
[將autoDeploy和deployOnStartup設爲false,並將全部的Context定義在server.xml中;
將WAR或者目錄放在虛擬主機的appBase外,並使用帶有docBase屬性的context.xml文件來定義它。]
Defining a context(定義一個context)
It is NOT recommended to place <Context> elements directly in the server.xml file. This is because it makes modifying the Context configuration more invasive since the main conf/server.xml file cannot be reloaded without restarting Tomcat.
[咱們不建議將<Context>元素直接放在server.xml文件中,這樣不便於修改Context配置,由於咱們只能經過重啓Tomcat才能從新裝載conf/server.xml。]
Individual Context elements may be explicitly defined:
In an individual file at /META-INF/context.xml inside the application files. Optionally (based on the Host's copyXML attribute) this may be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to application's base file name plus a ".xml" extension.
In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The context path and version will be derived from the base name of the file (the file name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.
Inside a Host element in the main conf/server.xml.
[單個的Context元素能夠被顯示的定義在:
應用文件的/META-INF/context.xml中,該文件可能被拷貝到$CATALINA_BASE/conf/[enginename]/[hostname]/目錄下(取決於Host元素中的copyXML屬性),並被重命名爲應用名.xml。
$CATALINA_BASE/conf/[enginename]/[hostname]/目錄下的以.xml爲後綴名的文件中,context路徑和版本會從基本文件名(即文件名中除去.xml後綴)中讀取。該文件的優先級老是高於web應用的META-INF的context.xml文件。]
Default Context elements may be defined that apply to multiple web applications. Configuration for an individual web application will override anything configured in one of these defaults. Any nested elements, e.g. <Resource> elements, that are defined in a default Context will be created once for each Context to which the default applies. They will not be shared between Context elements.
[能夠定義默認的Context元素供多個web應用使用,該配置會被單個web應用的配置覆蓋。在默認的Context中定義的嵌套元素(好比<Resource>元素)都不是共享的,而是對使用該默認Context的每一個應用都會建立一個。]
In the $CATALINA_BASE/conf/context.xml file: the Context element information will be loaded by all web applications.
In the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all web applications of that host.
[在$CATALINA_BASE/conf/context.xml文件中的Context元素信息會被全部的web應用加載。
在$CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default文件中的Context元素信息會被該主機下的全部web應用加載。]
With the exception of server.xml, files that define Context elements may only define a single Context element.
[除了在server.xml文件中能夠定義多個Context元素外,其餘定義Context元素的文件中只能定義一個Context元素。]
In addition to explicitly specified Context elements, there are several techniques by which Context elements can be created automatically for you. See Automatic Application Deployment and User Web Applications for more information.
[除了顯示的定義Context元素,還有其餘幾種技術能夠自動生成Context元素。參考Automatic Application Deployment和User Web Application來獲取這方面更多的信息。]
To define multiple contexts that use a single WAR file or directory, use one of the options described in the Naming section above for creating a Context that has a path that is not related to the base file name.
[若是要使用一個WAR文件或目錄來定義多個context,可使用命名(Naming)部分描述的操做,即建立一個路徑與文件基本名不關聯的Context。]
Attributes(屬性)
Common Attributes(公共屬性)
All implementations of Context support the following attributes:
[全部Context實現支持如下屬性:
這裏只列出出了目前我會用到的屬性,其餘屬性前參考tomcat的相關文檔。]
屬性 |
描述 |
className |
Java class name of the implementation to use. This class must implement the org.apache.catalina.Context interface. If not specified, the standard value (defined below) will be used. [Context實現所使用的Java類名,該類必須實現org.apache.catalina.Context接口。若是沒有指定,則使用標準實現(在下面定義)] |
cookies |
Set to true if you want cookies to be used for session identifier communication if supported by the client (this is the default). Set to false if you want to disable the use of cookies for session identifier communication, and rely only on URL rewriting by the application. [若是你想利用cookies來傳遞session標識號(須要客戶端支持cookies,默認狀況下是支持的),則設爲true。若是設置爲false,則不能經過cookies來傳遞session標識號,而只能經過URL重寫來傳遞。] |
crossContext |
Set to true if you want calls within this application to ServletContext.getContext() to successfully return a request dispatcher for other web applications running on this virtual host. Set to false (the default) in security conscious environments, to make getContext() always return null. [若是想在應用中調用ServletContext.getContext()來返回在該虛擬主機上運行的其餘web應用的request dispatcher,則設爲true。在安全性很重要的環境中,應將其設爲false,使得getContext()老是返回null。缺省值爲false。] |
docBase |
The Document Base (also known as the Context Root) directory for this web application, or the pathname to the web application archive file (if this web application is being executed directly from the WAR file). You may specify an absolute pathname for this directory or WAR file, or a pathname that is relative to the appBase directory of the owning Host. [該web應用的文檔基準目錄(Document Base,也稱爲Context Root) ,或者是WAR文件的路徑(若是該web應用是直接經過WAR文件執行的)。可使用絕對路徑,也可使用相對於對應的Host元素中的appBase屬性的路徑。] The value of this field must not be set unless the Context element is defined in server.xml or the docBase is not located under the Host's appBase. [除非Context元素被定義在server.xml中或者docBase不在Host的appBase下,不然不該該設置該屬性值。] If a symbolic link is used for docBase then changes to the symbolic link will only be effective after a Tomcat restart or by undeploying and redeploying the context. A context reload is not sufficient. [若是docBase使用的是符號連接,則只有當Tomcat重啓或者重載web應用時,對於符號連接的改變纔會生效。重載web應用不是高效的作法。] |
override |
Set to true to ignore any settings in both the global or Host default contexts. By default, settings from a default context will be used but may be overridden by a setting the same attribute explicitly for the Context. [若是想利用該Context元素中的設置覆蓋DefaultContext中相應的設置,設爲true。] |
path |
The context path of this web application, which is matched against the beginning of each request URI to select the appropriate web application for processing. All of the context paths within a particular Host must be unique. If you specify a context path of an empty string (""), you are defining the default web application for this Host, which will process all requests not assigned to other Contexts. [web應用的context路徑。Catalina將每一個請求URI的起始與context路徑進行匹配,選擇合適的web應用來處理該請求。特定Host下的context路徑必須是惟一的。若是context路徑爲空字符串(""),則該應用是該Host下的缺省web應用,用來處理全部不能匹配任何Context的請求。] This attribute must only be used when statically defining a Context in server.xml. In all other circumstances, the path will be inferred from the filenames used for either the .xml context file or the docBase. [只有當在server.xml中靜態地定義一個Context,才能使用該屬性。其餘狀況下,該屬性應該從.xml context文件或者是docBase所使用的文件名中推斷出來] Even when statically defining a Context in server.xml, this attribute must not be set unless either the docBase is not located under the Host's appBase or both deployOnStartup and autoDeploy are false. If this rule is not followed, double deployment is likely to result. [即便是在server.xml中靜態地定義一個Context,除非docBase不在Host的appBase下,或者autoDeploy和deployOnStartUp屬性都爲false,不然該屬性也不能被設置。若是不遵循這條規則,極可能會出現二次部署。] |
privileged |
Set to true to allow this context to use container servlets, like the manager servlet. Use of the privileged attribute will change the context's parent class loader to be the Server class loader rather than the Shared class loader. Note that in a default installation, the Common class loader is used for both the Server and the Shared class loaders. [若是設爲true,則容許context使用container servlets,好比manager servlet。使用該屬性將會將context的父類加載器由Shared類加載器變爲Server類加載器。注意,在默認安裝中, Server和Shared類加載器都會使用Common類加載器。] |
reloadable |
若是但願Catalina監視/WEB-INF/classes/和/WEB-INF/lib下的類是否發生變化,並在發生變化時自動重載web應用,則設爲true。這個特徵在開發階段頗有用,但也會大大增長服務器的開銷,所以,在發佈應用時不推薦使用。你可使用Manager應用在必要時重載應用。 |
swallowOutput |
If the value of this flag is true, the bytes output to System.out and System.err by the web application will be redirected to the web application logger. If not specified, the default value of the flag is false. [若是設爲true,則System.out和System.err的輸出被從定向到該web應用的logger中。若是沒有指定,則缺省值爲false。] |
wrapperClass |
指定org.apache.catalina.Wrapper實現類的名稱,用於該Context管理的servlets。若是沒有指定,則使用標準的缺省值。 |
Standard Implementation(標準實現)
The standard implementation of Context is org.apache.catalina.core.StandardContext. It supports the following additional attributes (in addition to the common attributes listed above):
[Context的標準實現是org.apache.catalina.core. StandardContext,它還支持以下的附加屬性:
這裏只列出出了目前我會用到的屬性,其餘屬性前參考tomcat的相關文檔。]
屬性 |
描述 |
useNaming |
Set to true (the default) to have Catalina enable a JNDI InitialContext for this web application that is compatible with Java2 Enterprise Edition (J2EE) platform conventions. [若是但願Catalina容許該web應用使用JNDI的InitialContext對象,則設爲true。缺省值是true。] |
workDir |
Pathname to a scratch directory to be provided by this Context for temporary read-write use by servlets within the associated web application. This directory will be made visible to servlets in the web application by a servlet context attribute (of type java.io.File) named javax.servlet.context.tempdir as described in the Servlet Specification. If not specified, a suitable directory underneath $CATALINA_BASE/work will be provided. [該Context提供的臨時目錄的路徑,用於servlet的臨時讀寫。利用javax.servlet.context.tempdir屬性,servlet能夠訪問該目錄。若是沒有指定,則使用$CATALINA_BASE/work下的一個合適的目錄。] |
Nested Components(嵌套組件)
You can nest at most one instance of the following utility components by nesting a corresponding element inside your Context element:
[下列元素能夠嵌套在Context元素中,但每一個元素至多隻能嵌套一次。]
Loader - Configure the web application class loader that will be used to load servlet and bean classes for this web application. Normally, the default configuration of the class loader will be sufficient.
[Loader - 配置該web應用的類加載器,用來加載servlet和bean類。正常狀況下,使用缺省的類加載器就足夠了。]
Manager - Configure the session manager that will be used to create, destroy, and persist HTTP sessions for this web application. Normally, the default configuration of the session manager will be sufficient.
[Manager - 配置session manager,用來建立、銷燬、以及維持該web應用的HTTP session。正常狀況下,使用缺省的session manager配置就足夠了。]
Realm - Configure a realm that will allow its database of users, and their associated roles, to be utilized solely for this particular web application. If not specified, this web application will utilize the Realm associated with the owning Host or Engine.
[Realm - 配置realm,該realm的用戶數據庫以及相關的角色僅用於該web應用。若是沒有指定,該web應用將會使用其所屬的Host或Engine的Realm]
Resources - Configure the resource manager that will be used to access the static resources associated with this web application. Normally, the default configuration of the resource manager will be sufficient.
[Resources - 配置resource manager,用於訪問與該web應用相關的靜態資源。正常狀況下,使用缺省的resource manager就足夠了。]
WatchedResource - The auto deployer will monitor the specified static resource of the web application for updates, and will reload the web application if it is updated. The content of this element must be a string.
[WatchedResource - 自動部署器(the auto deployer)會監視該web應用中指定的靜態資源是否更新,若是更新的話,會自動重載web應用。該元素的內容必須是一個字符串。]
Special Features(專有特徵)
Access Logs(訪問日誌)
When you run a web server, one of the output files normally generated is an access log, which generates one line of information for each request processed by the server, in a standard format. Catalina includes an optional Valve implementation that can create access logs in the same standard format created by web servers, or in any number of custom formats.
[正常狀況下,運行web服務器會生成訪問日誌,該日誌以標準格式爲每一個請求輸出一行信息。Catalina包含一個可選的Valve實現,該實現能夠用web服務器建立的標準格式或者用戶自定義的格式生成訪問日誌。]
You can ask Catalina to create an access log for all requests processed by an Engine, Host, or Context by nesting a Valve element like this:
[經過在Engine、Host或者Context中嵌套一個Valve元素,Catalina會爲該容器處理的全部請求建立訪問日誌,以下所示:]
See Access Logging Valves for more information on the configuration attributes that are supported.
[參考Access Loggin Valves,以得到更多配置屬性的信息。]
Automatic Context Configuration(Context的自動配置)
If you use the standard Context implementation, the following configuration steps occur automatically when Catalina is started, or whenever this web application is reloaded. No special configuration is required to enable this feature.
[若是使用標準的Context實現,當Catalina啓動時,或者從新裝載web應用時,以下的配置步驟會自動發生,不須要特殊的配置來使能這個特性。]
If you have not declared your own Loader element, a standard web application class loader will be configured.
If you have not declared your own Manager element, a standard session manager will be configured.
If you have not declared your own Resources element, a standard resources manager will be configured.
The web application properties listed in conf/web.xml will be processed as defaults for this web application. This is used to establish default mappings (such as mapping the *.jsp extension to the corresponding JSP servlet), and other standard features that apply to all web applications.
The web application properties listed in the /WEB-INF/web.xml resource for this web application will be processed (if this resource exists).
If your web application has specified security constraints that might require user authentication, an appropriate Authenticator that implements the login method you have selected will be configured.
[若是沒有自定義Loader元素,將會配置一個標準的web應用類加載器;
若是沒有自定義Manager元素,將會配置一個標準的session manager;
若是沒有自定義Resources元素,將會配置一個標準的resources manager;
在cong/web.xml文件中列出的web應用的屬性會被當作該web應用的缺省屬性,被用來創建缺省的映射(好比將.jsp映射成對應的JSP servlet),以及其餘標準特性;
/WEB-INF/web.xml resource中的屬性將被處理(若是該resource存在);
若是web應用指定了安全限制,而且可能須要對用戶進行認證,Catalina會配置選定的Authenticator,該Authenticator實現了login方法。]
Context Parameters(Context參數)
You can configure named values that will be made visible to web applications as servlet context initialization parameters by nesting <Parameter> elements inside this element. For example, you can create an initialization parameter like this:
[你能夠在Context元素中嵌套<Parameter>元素來配置帶有名稱的值,這些值會做爲servlet context的初始化參數,對整個web應用可見。好比,你能夠像這樣建立初始化參數:]
This is equivalent to the inclusion of the following element in the web application deployment descriptor (/WEB-INF/web.xml):
[這與在web應用的deployment descriptor(即/WEB-INF/web.xml)中包含以下元素等價:]
but does not require modification of the deployment descriptor to customize this value.
[區別是前者不須要修改deployment descriptor來定製這個值。]
The valid attributes for a <Parameter> element are as follows:
[<Parameter>元素的有效屬性以下:]
屬性 |
描述 |
descriptiont |
關於該context初始化參數的文字描述(可選) |
name |
要建立的context初始化參數的名稱 |
override |
若是不但願在該web應用中的/WEB-INF/web.xml文件中具備相同參數名稱的<context-param>覆蓋這裏的值,則設爲false。缺省值爲true。 |
value |
調用ServletContext.getInitParameter()時,返回給應用的參數值。 |
Environment Entries(環境條目)
You can configure named values that will be made visible to web applications as environment entry resources, by nesting <Environment> entries inside this element. For example, you can create an environment entry like this:
[你能夠在Context元素中嵌套< Environment >元素來配置帶有名稱的值,這些值會做爲環境條目資源(environment entry resources),對整個web應用可見。好比,你能夠像這樣建立一個環境條目:]
This is equivalent to the inclusion of the following element in the web application deployment descriptor (/WEB-INF/web.xml):
[這與在web應用的deployment descriptor(即/WEB-INF/web.xml)中包含以下元素等價:]
but does not require modification of the deployment descriptor to customize this value.
[區別是前者不須要修改deployment descriptor來定製這個值。]
The valid attributes for an <Environment> element are as follows:
[<Environment >元素的有效屬性以下:]
屬性 |
描述 |
descriptiont |
關於該環境條目的文字描述(可選) |
name |
要建立的環境條目的名稱,相對於java:comp/env context |
override |
若是不但願在該web應用中的/WEB-INF/web.xml文件中具備相同參數名稱的<env-entry>覆蓋這裏的值,則設爲false。缺省值爲true。 |
type |
環境條目的java類名的全稱。在/WEB-INF/web.xml文件中的環境條目的<env-entry-type>的值必須是以下的值:java.lang.Boolean,java.lang.Byte,java.lang.Character,java.lang.Double,java.lang.Float,java.lang.Integer,java.lang.Long,java.lang.Short,java.lang.String。 |
value |
經過JNDI context請求時,返回給應用的參數值。這個值必須能夠被轉換爲type屬性中定義的Java類型 |
Lifecycle Listeners(生命週期監聽器)
If you have implemented a Java object that needs to know when this Context is started or stopped, you can declare it by nesting a Listener element inside this element. The class name you specify must implement the org.apache.catalina.LifecycleListener interface, and it will be notified about the occurrence of the coresponding lifecycle events. Configuration of such a listener looks like this:
[若是一個Java對象須要知道該Context什麼時候啓動,什麼時候中止,則能夠在該Context元素中嵌套一個Listener元素。指定的類名必需要實現org.apache.cataline.LifecycleListener接口,這樣,在發生對應的生命週期事件時就會通知該監聽器。能夠按照以下方法配置一個監聽器:]
Note that a Listener can have any number of additional properties that may be configured from this element. Attribute names are matched to corresponding JavaBean property names using the standard property method naming patterns.
[注意,一個監聽器能夠配置任意多的附加屬性,屬性名與JavaBean的屬性名相對應,且要使用標準的屬性命名方法。]
Request Filters(請求過濾器)
You can ask Catalina to check the IP address, or host name, on every incoming request directed to the surrounding Engine, Host, or Context element. The remote address or name will be checked against configured "accept" and/or "deny" filters, which are defined using java.util.regex Regular Expression syntax. Requests that come from locations that are not accepted will be rejected with an HTTP "Forbidden" error. Example filter declarations:
[對於每一個發送到Engine、Host、或者Context的請求,能夠要求Catalina檢查IP地址或主機名,Catalina會使用一系列配置好的"accept"和"deny"過濾器對遠程地址或主機名進行檢查。過濾器使用java.util.regex中的正則表達式語法定義。不被接受的請求會返回一個HTPP "Forbidden"錯誤。過濾器聲明的例子以下:]
see Remote Address Filter and Remote Host Filter for more information about the configuration options that are supported.
[參考Remote Address Filter和Remote Host Filter,獲取更多配置方面的信息。]
Resource Definitions(資源定義)
You can declare the characteristics of the resource to be returned for JNDI lookups of <resource-ref> and <resource-env-ref> elements in the web application deployment descriptor. You MUST also define the needed resource parameters as attributes of the Resource element, to configure the object factory to be used (if not known to Tomcat already), and the properties used to configure that object factory.
[能夠在/WEB-INF/web.xml中定義資源的特性,使用JNDI查找<resource-ref>和<resource-env-ref>元素時,將會返回這些特性。你還必須定義資源參數做爲Resource元素的屬性,另外,這些資源參數還會被用來配置對象工廠以及配置對象工廠的屬性。]
For example, you can create a resource definition like this:
[好比,你能夠按照如下方式來建立一個資源:]
This is equivalent to the inclusion of the following element in the web application deployment descriptor (/WEB-INF/web.xml):
[這與在web應用的deployment descriptor(即/WEB-INF/web.xml)中包含以下元素等價:]
but does not require modification of the deployment descriptor to customize this value.
[區別是前者不須要修改deployment descriptor來定製這個值。]
The valid attriutes for a <Resource> element are as follows:
[<Resource >元素的有效屬性以下:]
屬性 |
描述 |
auth |
指定是由web應用代碼自己簽署到資源管理器,仍是由Container表明該web應用簽署(sign on)到資源管理器(resourcemanager)。該屬性的值必須是Application或者Container。若是web應用要使用到在/WEB-INF/web.xml中定義的<resource-ref>,則該屬性是必須的;若是web應用使用的是<resource-env-ref>,則該屬性是可選的。 |
closeMethod |
表示一個沒有參數的方法的名稱。當一個單例資源再也不須要時,調用此方法,這種作法的好處是提升了對資源的清理速度,而不是由垃圾回收機制來回收該資源。若是singleton屬性爲false,則該屬性被忽略。該屬性沒有缺省值,若是沒有指定,則不會調用任何關閉方法。 對於Apache Commons DBCP 和 Apache Tomcat JDBC鏈接池,可使用closeMethod="close" |
descriptiont |
關於該資源的文字描述(可選) |
name |
要建立的資源的名稱,相對於java:comp/env context |
override |
若是不但願在該web應用中的/WEB-INF/web.xml文件中具備相同參數名稱的<env-entry>覆蓋這裏的值,則設爲false。缺省值爲true。 |
scope |
指定經過該資源管理器獲得的鏈接是否能夠被共享。該屬性的值必須是Shareable或者Unshareable。缺省狀況下,假定鏈接是可共享的。 |
singleton |
指定該資源定義是否爲一個單例資源服務。若是設爲true,則對該資源的屢次JNDI查找都會返回相同的對象;若是設爲false,則對該資源的屢次JNDI查找會返回不一樣的對象。對於javax.sql.DataSource資源,該屬性必須設爲true,來使能該數據源的JMX註冊。該屬性的值必須是true或false,缺省爲true。 |
type |
當web應用查找該資源時須要的Java類的全稱。 |
Resource Links(資源鏈接)
This element is used to create a link to a global JNDI resource. Doing a JNDI lookup on the link name will then return the linked global resource.
[該元素用來建立到全局JNDI資源的連接,在連接名稱上進行JNDI查找會返回被連接的全局資源。]
For example, you can create a resource link like this:
[好比,你能夠按照以下方法建立一個資源連接:]
The valid attributes for a <ResourceLink> element are as follows:
[<ResourceLink>元素的有效屬性以下:]
屬性 |
描述 |
global |
全局JNDI context中被連接的全局資源的名稱。 |
name |
要建立的資源連接的名稱,相對於java:comp/env context。 |
type |
當web應用在該資源連接上進行查找時,返回的Java類名的全稱。 |
factory |
建立這些對象所使用的Java類名的全稱。該類應該實現javax.naming.spi.ObjectFactory接口 |