简体   繁体   English

使用[context] .xml和web.xml配置Web应用程序

[英]use of [context].xml and web.xml for configuring web app

I just learned that I could retrieve parameters and other stuff from "ServletContext" (ie by overriding contextInitialized). 我刚刚了解到我可以从“ServletContext”中检索参数和其他内容(即通过覆盖contextInitialized)。

Reading tomcats context doc reveals that I could set parameters via web.xml (used as default values) and then overwrite them with an [context].xml file. 读取tomcats上下文文档显示我可以通过web.xml设置参数(用作默认值),然后用[context] .xml文件覆盖它们。

First question: is this a good way to set default properties and let server administrators overwrite them? 第一个问题:这是设置默认属性并让服务器管理员覆盖它们的好方法吗?

First is there an overview that shows all kinds of attributes/parameters that are available with it's tag used in tomcats context xml, the tag used in web xml, how the retrieve it from within java and a use case / example for what kind of stuff a parameter should be used? 首先是概述,它显示了tomcats context xml中使用的标签所提供的各种属性/参数,web xml中使用的标签,如何从java中检索它以及用例/示例用于什么样的东西应该使用一个参数?

By toying around with it I am facing the following problem: If I deploy the web app via tomcats web interface the [context].xml is completly ignored (console states that it is deployed but 2nd is null) 通过玩弄它我面临以下问题:如果我通过tomcats web界面部署Web应用程序,[context] .xml被完全忽略(控制台声明它已部署,但2nd为null)

To cut a long story short: how to properly use web.xml and [context].xml - the link below isn't much help. 简而言之:如何正确使用web.xml和[context] .xml - 下面的链接没有多大帮助。

Well first off, declaring (servlet/application) context attributes via web.xml is better, as this is the official Java EE supported way, so if you declare them like this they will work when you deploy your app in other App Servers other than Tomcat. 首先,通过web.xml声明(servlet / application)上下文属性更好,因为这是Java EE支持的官方方式,所以如果你这样声明它们,那么当你在除了Tomcat的。

Second, I believe the Tomcat rule for overriding param values is: 其次,我相信覆盖param值的Tomcat规则是:

if you have a $CATALINA_BASE/conf/context.xml and you have the same attribute declared in it and in web.xml, the one in web.xml will have priority 如果你有$ CATALINA_BASE / conf / context.xml并且你在web.xml和web.xml中声明了相同的属性,那么web.xml中的属性将具有优先级

if you have a $CATALINA_BASE/conf/context.xml as well as a context.xml file inside your application (in the META-INF directory) both with the same parameter, the one in the META-INF/context.xml will have priority. 如果您的应用程序(在META-INF目录中)有一个$ CATALINA_BASE / conf / context.xml以及一个带有相同参数的context.xml文件,那么META-INF / context.xml中的那个将具有优先。

Finally, if you have all three files decalring the same parameter, the one in the web.xml will have priority. 最后,如果所有三个文件都使用相同的参数,则web.xml中的文件将具有优先级。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM