On Tue, 19 Dec 2000, Guillaume Barreau wrote:

> Dear Tomcat users,
> 
> What is the best way to create some objects which are going to be available
> application-wide to a bunch of servlets from the same web-app? Or in other
> words, is there an equivalent of an init() method but for the application as a
> whole?
> 
you could use the <jsp:useBean ... scope="application" /> tag.
it's not only handy for beans, but for other objects that need to have 
an application scope too.

> At the moment, I am having to clutter the init() method of all my servlets with
> code to check if the object has been created and create it if it hasn't. I have
> to do that because I am not sure which servlet will be invoked first. 
> 
hm. what's wrong with a singleton for the objects? 
you just access them with: 
ApplicationWideObject x=ApplicationWideObject.getInstance();

> Am I missing something? Is there any way to do that in the xml descriptor file?

Am I missing something,
or is the answer enough.

have fun,

Sloot.

Reply via email to