Tomcat翻译--Context Container

原文:http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Definitions

The Context Container(Context容器)

Introduction(介绍)

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相同。]

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应用程序开发者指南。]

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.

 [通过将请求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接口 

posted @ 2015-12-11 15:15  codeplayplus  阅读(867)  评论(0编辑  收藏  举报