dermoritz
dermoritz

Reputation: 12991

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

I just learned that I could retrieve parameters and other stuff from "ServletContext" (i.e. 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.

Upvotes: 4

Views: 5741

Answers (1)

Shivan Dragon
Shivan Dragon

Reputation: 15219

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.

Upvotes: 4

Related Questions