Re: How can I get a context (application) init parameter from a javabean
Posted By:
AlessandroA_Garbagnati
Posted On:
Wednesday, May 2, 2001 10:09 AM
Guido,
There are two ways to solve this problem. The first one is more complex and it's based on the bean reading those values directly from the file. As you can immagine, this can be a problem (os dependancy, no portability).
The other solution is to have a method in your bean that receives a ServletContext as a parameter and extract the parameters from that object.
The reason is simple: the bean has absolutely no knowledge about that file and the only way to fix this is to provide it the location (so you can read it) or an object that knows it (the context).
I think that you would like to use the bean almost like a singleton that handles your db connection. You can create a servlet that it is loaded at startup (so init() it's executed when the servlet container starts) that has in the init() method the logic for reading the values and pass them to the bean. I think that this is a widely used solution.