tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Evans <>
Subject RE: Accessing resource in WEB-INF outside servlet
Date Mon, 08 Nov 2004 14:18:59 GMT
Thanks for the reply. So the next question of course is, what is a
better approach? I understand idea of using putting an object in the
ServletContext during application initialization, but that leads to
other problems. 

Well, to be specific, heres the problem i have with that in my

i have static DAO classes, one per database table, that my application
uses to handle persistance of my applications business objects. So i
need the connection information for the database. i have other
application instance specific variables also, directory paths for
templates and upload. So originally i wrote a AppConfig class that had
properties for all these variables, and a factory class that read an xml
file, and created a instance of the AppConfig class and stuck it in the
ServletContext during initialization. But the DAO classes are static
classes, and should be usable by any java program, not just a Servlet.
They currently have a very clean API, for instance:

public static Book getBook(String bookId)
public static void updateBook(Book book)

So in order to preserve that cleanliness, the methods have to get the
connection path themselves, which was why i was so excited by the JNDI

So any advice?


On Mon, 2004-11-08 at 08:59, Shapira, Yoav wrote:
> Hi,
> >Is using JNDI to access a file like this a reasonable approach? I just
> It's an OK approach.  Not great, but not terrible either.  The reasons
> it's not great are:
> - It's heavyweight (JNDI resource binding and resolution is typically
> several times more resource consuming than a static resource lookup via
> either the classpath or the ServletContext).  But if done once to
> initialize a variable, this is fairly negligible.
> - It's container-dependent: you need something to do the JNDI binding
> and lookups.  Running a small console app with this code becomes very
> difficult. And unit testing it as-is becomes exceedingly difficult.
> - It's awkward to change: you need to modify a container-specific
> configuration file to change the entry.  This is both a pro and con,
> though, as it means the server admin running your app can modify this
> without needing programmer intervention.  
> So it'll work, but the above merit consideration.
> Yoav
> This e-mail, including any attachments, is a confidential business communication, and
may contain information that is confidential, proprietary and/or privileged.  This e-mail
is intended only for the individual(s) to whom it is addressed, and may not be saved, copied,
printed, disclosed or used by anyone else.  If you are not the(an) intended recipient, please
immediately delete this e-mail from your computer system and notify the sender.  Thank you.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message