You didn't mention the possibility of putting the class in the
ServletContext.

I asked about the same question a week ago, but got no answer ;-(
So I guess It's OK to use a singleton or static class like you do.
It's no real singleton, because (I think that) there's an instance for each
classloader. So JSP and servlets could possible use another instance.
I think it's best to make a real sibngleton object, but there's nothing that
prevents you from making a static getinfo() function that acts as a wrapper
function for the instance getInfo() (well, you'll need to give it a slightly
different name ;-)
that way you can either use
PackageName.Config.getInstance().getInfo("fileroot")
or
PackageName.Config.info("fileroot")

Geert 'Darling' Van Damme

> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of jimmy lopez
> Sent: woensdag 3 november 1999 15:41
> To: [EMAIL PROTECTED]
> Subject: Wrapping a Config class (singleton) as a Bean
>
>
> Hi,
>
> Can anyone help me with the following (related) problems.
>
> I inherited a JSP-based application (no servlets, no beans) which uses in
> many places a Java class (Config.java) which wraps a
> configuration file that
> looks like this:
> fileroot=http://192.125.105.160/
> mailhost=http://192.125.105.110/mail/
> ...
>
> This Config class is used by other classes (implementing the Application
> logic) and is used in the JSPs by accessing the class method
> 'getInfo()' in
> this way:
> <%= PackageName.Config.getInfo("fileroot") %>
>
> 1. My first problem (more a Java problem than a JSP one) concerns the
> Config.java class. It seems to me that this class should be
> implemented as a
> singleton class (its unique instance represents a singular entity in the
> system) but this seems to add a overhead (avoiding its
> garbage-collection).
> Any suggestion?
>
> 2. In the new design of the application (in which I want to separate the
> different -MVC - logics), I am still wandering if I can wrap the Config
> class (as it stands) as a JavaBean, and use it in both JSP files and Java
> classes. Knowing that in the JSPs only one method (getInfo())
> will be used,
> what would be the best solution?
>
> 3. If the answer to my first problem is that the Config.java should be a
> singleton, how can I do if I want to wrap it as a bean?
>         I would like to avoid having in my JSPs something like this:
>         <%= PackageName.Config.getInstance().getInfo("fileroot") %>
>
>
> Hope this is clear enough.
> Thanks in advance.
>
> Jimmy.
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
>
> ==================================================================
> =========
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> FAQs on JSP can be found at:
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to