开发者

Is it possible to define initial parameter arguments for Java webapp listeners?

开发者 https://www.devze.com 2022-12-14 16:34 出处:网络
In a web application\'s web.xml file, one can define initial parameters for servlets and filters by using the init-param element.Parameters defined here can then be retrieved by calling getServletConf

In a web application's web.xml file, one can define initial parameters for servlets and filters by using the init-param element. Parameters defined here can then be retrieved by calling getServletConfig(). It does not seem possible to do the same with listeners, as the DTD only defines the listener-class element there.

I would really rather not resort to having a bunch of random properties files (or even worse, more XML 开发者_C百科configuration ones) inside of my webapp, but I'm not sure how I can otherwise pass data to my listeners during initialization. Any ideas?


You can define initialisation parameters for the context as a whole, and get those from the ServletContext object.

If your listener implements ServletContextListener then you can grab the initialisation parameters when receiving the contextInitialized event.

0

精彩评论

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