0

On The Context Container page of the Tomcat documentation, I see two sections:

The standard names for such elements is <context-param> and <env-entry>, while the Tomcat-specific names are <Parameter> and <Environment>.

Both Context Parameters and Environment Entries appear to have the same simple job of making same value available to the servlets running in that context. For example, setting a flag to communicate some condition.

➥ What is the difference between Context Parameters and Environment Entries?

➥ Why would I choose to use one instead of the other?

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
  • 1
    Possible duplicate of [Servlet-spec: vs in web.xml?](https://stackoverflow.com/questions/13196868/servlet-spec-context-param-vs-env-entry-in-web-xml) – Ioannis Barakos Oct 14 '19 at 10:09

1 Answers1

2

What is the difference between Context Parameters and Environment Entries?

This is the same answer as Servlet-spec: <context-param> vs <env-entry> in web.xml??

Why would I choose to use one instead of the other?

I'm assuming that you mean "why would I choose <Context>/<Environment> versus <context-param>/<env-entry>" and not "how do I decide if I want a context parameter or an environment entry". If your question is the latter, than your question is indeed a duplicate.

The reason you might want to use <Context>/<Environment> in META-INF/context.xml versus putting their analogues into WEB-INF/web.xml comes down to separation of duties in a deployment scenario. Generally speaking, programmers are the ones who are in charge of the contents of WEB-INF/web.xml and administrators or operations staff are in charge of the contents of META-INF/context.xml.

Operators can override values specified by programmers for, say, the location of a configuration file. WEB-INF/web.xml might point to a configuration file in ~/configs/app.conf while the production deployment puts that configuration file into /etc/foo/app.conf.

It's better if operators aren't making on-the-fly changes to an application's deployment descriptor. META-INF/context.xml allows them to make those kinds of adjustments without changing that deployment descriptor.

If you are a one-person operation or if everyone is DevOps or whatever, then it almost doesn't matter. But Tomcat gives you the flexibility to implement whatever policy you want to enforce in your own environment.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
  • Thank you much. By the way, if you want a tougher nut to crack, perhaps you would like to explain [how to specify a `DataSource` object factory instead of Tomcat’s default](https://stackoverflow.com/q/58385528/642706). – Basil Bourque Oct 18 '19 at 21:06