tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: ServletContext.getResourceAsStream() in 3.2?
Date Tue, 12 Dec 2000 00:23:11 GMT
Sean Dowd wrote:

> I'm trying to load a properties file at startup in a servlet by doing a
>
> ClassLoader loader = Thread.currentThread().getContextClassLoader();
> InputStream is = null;
> is = getServletContext().getResourceAsStream( propFileName );
> while(loader != null && is == null) {
>   is = loader.getResourceAsStream( propFileName );
>   loader = loader.getParent();
> }
>
> This is returning null under tomcat 3.2 but worked fine under 3.1.  The
> file
> exists in my classes directory under WEB-INF.
>
> I've tried this with a leading / on the file name and without a leading
> / with the
> same results.  The web app is defined in my server.xml and resides
> outside of
> $TOMCAT_HOME/webapps.
>

If you want to load a file that is under WEB-INF, you don't need to involve the
class loader at all.  Simply use:

    InputStream is =
      getServletContext().getResourceAsStream("/WEB-INF/myprops.properties");

Craig McClanahan



Mime
View raw message