I also have lots of this sort of nonsense.
My planned solution is to have only one servlet. This will act as a broker
to load 'logic modules', which are invoked thru' the url with xtra path
info:
http://myServer/myServlet/myModule?yada=yada&foo=bar
This has lots of potential advantages as all requests to a given webapp will
be processed by the same servlet, making many things easier. The myModule
will then implement an interface/extend functionality of my choosing, rather
than being saddled with the servlet spec. The servlet will just load on
startup, and any application-scope objects ith it.
-----Original Message-----
From: Alex Fernández [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 19, 2000 1:27 PM
To: [EMAIL PROTECTED]
Subject: Re: creation of application wide objects
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.