Servlet-spec: vs in web.xml?

后端 未结 1 1980
予麋鹿
予麋鹿 2021-01-02 07:05

Why does the Servlet specification define two distinct ways (context parameters and environment entries) to provide a web application with configuration parameters?

1条回答
  •  一整个雨季
    2021-01-02 07:49

    Environment entries are available via JNDI which may be useful when you don't have a ServletContext directly at hands, such as in EJBs. The one in the web.xml is actually the last in precedence chain as to overridding environment entires. They are usually definied in server's own configuration. So if one intends to override a server-specified environment entry from the webapp on, then that could be done via web.xml.

    Context parameters are really specific to the webapp itself. They are only available when you have a ServletContext directly at hands, usually only inside filters, servlets (and inherently also JSPs via ${initParam.someName} in EL) and listeners. They are supposed to be used to provide configuration parameters for filters, servlets and/or listeners running in the webapplication. It wouldn't make much sense to provide them by JNDI which is an overcomplicated process for the simple purpose.

    0 讨论(0)
提交回复
热议问题