views:

62

answers:

1

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 configuration ones) inside of my webapp, but I'm not sure how I can otherwise pass data to my listeners during initialization. Any ideas?

+3  A: 

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.

araqnid
+1: there you indeed have the `<context-param>` for.
BalusC
I never knew that these could be defined in the web.xml -- but it's exactly what I was looking for. Thanks!
Nik Reiman