Miles Daffin wrote:
> Hi guys,
>
> > > From the looks of things, it is just the way it is, although I was
> hoping
> > > the there would be some way to put stuff in the web.xml file, maybe in
> the
> > > servlet tag like:
> > >
> > > <system-property>
> > > <name>myproperty</name>
> > > <value>42</value>
> > > </system-property>
> > >
> > > Anyone think this is a good idea, or am I talking rubbish?
> >
> > It's a bad idea. Keep your web-apps encapsulated.
>
> Why would such a move, if it were possible, break encapsulation?
>
> As long as this property value is never broadcast
> i.e. System.setProperty("myProperty", "42");
>
System properties, in the sense that we are talking about the java.lang.System
class, are global to the entire JVM. Therefore, even if the statement above was
allowed, it would set the property "myProperty" for *all* web applications that
are installed in a single Tomcat instance, and would therefore cause a name
clash if another app also tried to set the value for "myProperty".
Context parameters, on the other hand, are unique to an individual web
application so there are no problems with two web-apps having parameters (or
anything else, for that matter) with the same names.
>
> If you want application local properties then simply create a class to hold
> them
> with a static method for obtaining them from anywhere in your app (like
> System.getProperties()).
>
You can use static variables for this purpose and get away with it, as long as
the classes involved are loaded from WEB-INF/classes or WEB-INF/lib. The reason
for this is that each web application is loaded by its own class loader, so
statics created by such classes are visible only within the web app. I have a
personal bias against statics (I prefer to store global application objects in
the servlet context, so that they are easily visible to all servlets and JSP
pages in my apps).
> Miles
Craig