Rodrigo Gevaerd [mailto:[EMAIL PROTECTED]] wrote:
> I got an application that has several constants (for example,
> database url). The application consists of several JSPs for
> presentation and classes for the persistence.
>
> How can I keep the application constants, so that 2 applications of
> this type (with different constants values) can co-exist in the same
> JVM (possibly in different web applications)?

     A lot depends on your particular platform - with a lot of
platforms you wouldn't in fact be using the same JVM.  Or rather, the
spec requires the platform to be implemented to use a different
classloader for each application, to make it appear to the program
that it's living in its very own JVM, and hence each application would
have its own singleton.  Check the 2.2 servlet spec and read up on
"web applications".

> It was developed initially keeping the constants in a singleton
> class. But with more than one application it cannot be done like
> that.

     A quick and dirty solution might be to, assuming the singleton
loads the constants from a properties file (and if it doesn't, it
should), edit the properties file so instead of:

db.url=http://blah.com
db.user=scott
db.password=tiger

     You would have:

app1.db.url=http://blah.com
app1.db.user=scott
app1.db.password=tiger
app2.db.url=http://blah.com
app2.db.user=scott
app2.db.password=tiger

     And then have all of the calls to the singleton use the
appropriate application name prefix.  This is a kludge, but that seems
to be what you're asking for.  Or alternatively, have the singleton
load in two different properties files and tweak
singleton.getInstance() to take a name string, and hand back a
different instance based on the name you use.

Steven J. Owens
[EMAIL PROTECTED]

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to