[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.webtools] Re: Tomcat/Servlet Resource File Location

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( "/WEB-INF/db.properties")

Error and exception handling to be added.

Cheers,
Larry


Hello,

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?

Cheers,
meta

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.

Cheers,
Larry