Hi folks!

I'm having the same problem, but with servlets. To summarize, I want to have some
kind of init() method, to perform some startup tasks, but for the whole application.

Right now, in every servlet's init() method I must call a singleton to perform the
job. So the problem is, can I do that some other way?

See below for comments.

[EMAIL PROTECTED] wrote:

> 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.

OK, is there a servlet equivalent?

> > 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();

Anyhow, it's still repetitive code in every servlet. I'd like something more
automatic.

Thanks,

Alex.

Reply via email to