java context.xml 和 server.xml 之间的区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11559689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 05:34:27  来源:igfitidea点击:

difference between context.xml and server.xml?

javajakarta-eetomcat

提问by saplingPro

what is the difference between context.xmlof Tomcat and server.xmlof Tomcat ? If I want to add a tag like :

之间有什么区别context.xml的Tomcat和server.xmlTomcat的呢?如果我想添加一个标签,如:

    <Resource name="jdbc/MyDs" auth="Container" type="javax.sql.DataSource"
     driverClassName="org.apache.derby.jdbc.ClientDriver"
     url="jdbc:derby://localhost:1527/my_database;create=true"
     username="me" password="me" maxActive="20" maxIdle="10" maxWait="-1" />

where should I add it ?

我应该在哪里添加它?

回答by hcg

The server.xml is used for server and context.xml is for application that runs on that server. There may be several context.xml files (per application) on a server but only one server.xml.

server.xml 用于服务器,context.xml 用于在该服务器上运行的应用程序。一台服务器上可能有多个 context.xml 文件(每个应用程序),但只有一个 server.xml。

回答by GlaIZier

Tomcat web application has a bunch of configs called deployment descriptors which can be separated in two groups: server-dependent (context.xml) and server-independent (web.xml).

Tomcat Web 应用程序有一堆称为部署描述符的配置,它们可以分为两组:依赖于服务器的 (context.xml) 和独立于服务器的 (web.xml)。

server.xml- stores on server side and describe the general configuration of Tomcat server. This file is the only one for a one Tomcat server.

server.xml- 存储在服务器端并描述 Tomcat 服务器的一般配置。这个文件是唯一一个用于一个 Tomcat 服务器的文件。

context.xml- can be stored on server side (conf/) or be embedded in a web app (META-INF/). This file contains server-dependent configuration like DataSources provided by Tomcat server.

context.xml- 可以存储在服务器端 (conf/) 或嵌入 Web 应用程序 (META-INF/)。该文件包含依赖于服务器的配置,如 Tomcat 服务器提供的数据源。

web.xml- can be stored on server side (conf/) or be embedded in a web app (WEB-INF/). This file contains server-independent configuration like servlet mappings.

web.xml- 可以存储在服务器端 (conf/) 或嵌入到 Web 应用程序 (WEB-INF/) 中。此文件包含独立于服务器的配置,如 servlet 映射。

Context.xml and web.xml on a server-side in the Tomcat conf/ directory are used to provide the default behavior of Tomcat, like default servlet mappings. Thus we have one server.xml per server and a pair context.xml/web.xml of files per a web application. If you want to share configuration between several application you should use server.xml (e.g. like it is for security Realms). Otherwise - server.xml/web.xml. In your case I suggest you to use web app embedded context.xml.

Tomcat conf/ 目录中服务器端的Context.xml 和web.xml 用于提供Tomcat 的默认行为,如默认servlet 映射。因此,我们每个服务器有一个 server.xml,每个 Web 应用程序有一对 context.xml/web.xml 文件。如果您想在多个应用程序之间共享配置,您应该使用 server.xml(例如,它用于安全领域)。否则 - server.xml/web.xml。在您的情况下,我建议您使用 Web 应用程序嵌入的 context.xml。

回答by shyam_prakash

This entry can go in server.xml under or in individual context files. Context xml files can be specific to each application deployment, whereas server.xml becomes global.

此条目可以位于单个上下文文件下或其中的 server.xml 中。上下文 xml 文件可以特定于每个应用程序部署,而 server.xml 变成全局的。

Application specific context files are usually located in catalina\localhost folder.

应用程序特定的上下文文件通常位于 catalina\localhost 文件夹中。