|Re: Tomcat/Servlet Resource File Location [message #484845 is a reply to message #484741]
||Wed, 09 September 2009 13:55
| Larry Isaacs
Registered: July 2009
Andreas H. wrote:|
> Larry Isaacs wrote on Tue, 08 September 2009 10:39
>> Andreas H. wrote:
>> > Hi,
>> > ...
>> > > cheers,
>> > meta
>> You could try something like the following to get an InputStream to
>> read the properties:
>> Servlet.getServletConfig().getServletContext().getResourceAs Stream(
>> Error and exception handling to be added.
> That could be some sort of a icky solution. Sorry I didn't add the
> following information: I'm calling a backend object that's not a servlet
> and this object was meant to handle everything, including database
> connection which i would have needed the properties file for. I don't
> have a Servlet in there to get the configuration from. Of course I could
> get the Path in the servlet and try to pass it to the backend, but
> that's what makes it icky in my opinion. Could there be another way?
Who is calling the backend object, and is it and/or the backend object
part of the web application?
The point is that ServletContext.getResource(),
ServletContext.getResourceAsStream(), Class.getResource() and
Class.getResourceAsStream() can all provide access to a resource within
a web application using a "path" that is guaranteed to work regardless
of deployment. Assuming the backend object is part of the web
application, a ServletContextListener could pass a ServletContext to the
backend object during web application initialization, or read the
properties and pass a Properties object.
Powered by FUDForum
. Page generated in 0.06450 seconds