Servlet规范:< context-param> vs< env-entry>在web.xml中? [英] Servlet-spec: <context-param> vs <env-entry> in web.xml?

查看:69
本文介绍了Servlet规范:< context-param> vs< env-entry>在web.xml中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 Servlet规范定义了两种不同的方式(上下文参数和环境)条目)为Web应用程序提供配置参数?

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

这些方法的优点分别是什么(何时应首选)?

What are the respective advantages of these approaches (when should which be preferred)?

推荐答案

可通过 JNDI 访问环境条目当您没有 ServletContext 直接使用,例如在 EJB 中. web.xml中的那个实际上是优先于覆盖整个环境的优先链.它们通常是在服务器自己的配置中定义的.因此,如果打算从Web应用程序覆盖服务器指定的环境条目,则可以通过web.xml来完成.

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.

上下文参数确实是特定于Webapp本身的.只有当您拥有 ServletContext 直接就在手边,通常仅在过滤器 JSP 通过EL )和

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.

这篇关于Servlet规范:< context-param> vs< env-entry>在web.xml中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆