简体   繁体   中英

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).

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.

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?

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)

To cut a long story short: how to properly use web.xml and [context].xml - the link below isn't much help.

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.

Second, I believe the Tomcat rule for overriding param values is:

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

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.

Finally, if you have all three files decalring the same parameter, the one in the web.xml will have priority.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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