开发者

How to gain access to a ServletContext instance from any method?

开发者 https://www.devze.com 2023-02-25 18:20 出处:网络
Is there any way to get access to the ServletContext from a method without passing the ServletContext as an argument?

Is there any way to get access to the ServletContext from a method without passing the ServletContext as an argument?

I need to have a ge开发者_开发技巧neric Configuration class that can work on several environments and load the config in a way depending on the environment.

For example, when in a web app, i need to get the configuration from either web.xml or a config file stored in WEB-INF.

But in order to know if the app is running in a web app i need to gain access to the ServletContext somehow.

Any ideas?


Have a class that holds servlet context as static field initilize it from ServletContextListener

0

精彩评论

暂无评论...
验证码 换一张
取 消