A general question about writing servlets...

I would like to have a class or object in my servlet where I can go to find
out misc. information
- the HttpServletRequest object
- authentication information (userid, permissions)
- database connection information
- audit management objects, and objects for loggin activity
etc.

If this was written as an application (instead of a servlet), then I could
do this using the 'Singleton' design pattern, and create a single instance
of a class.  Or as static methods and variables of a class.  But this won't
work for a servlet, because what's really needed is one instance for each
'request/session' that is being processed.

I know that I can tie things together with cookies or HttpSession objects.
But the problem is that I can't figure out a way around the fact that I
will need a handle to at least one object (for example, a handle to an
HttpSession object that could lead me to the other objects).

I don't think this is elegant, because I'd still have to pass an instance
of that object to every object/method that might need to get some
information.  There doesn't seem to be a global way to get it.  This also
means that many of my methods wouldn't even directly use the object, but
would have to carry that handle around as a parameter anyway, in case the
lower level methods need it.

Imagine, for example, if every method you write in any Java application
would need to have "System.out" passed to it, in case there is some method
that might need to print to the terminal.

Does anyone else feel this way?  Is there a preferred solution to this?  Or
do people write simple servlets where this isn't much of an issue?

Thanks
Alok Mehta, Research Scientist
Wadsworth Center, NYS Dept. of Health

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to