You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Timothy Stone <ci...@petmystone.com> on 2003/06/13 18:36:20 UTC
getResourceAsStream and relative paths in web.xml
List,
I'm following a twist on some advice that I got from Yoav Shapira. But
in playing to learn more I ran across something that I have not been
able to solve from reading the documentation.
I want to put the relative path to a user=password property file in the
web.xml. Given:
#web.xml
...
<servlet>
<servlet-name>ProtectedPage</servlet-name>
<servlet-class>coreservlets.ProtectedPage</servlet-class>
<init-param>
<param-name>passwordFile</param-name>
<param-value>/WEB-INF/lib/passwords.properties</param-value>
<!-- want to avoid making this absolute to the file system.
i.e. "c:\path\to\file"; naturally this is ugly and not
portable.
-->
</init-param>
</servlet>
...
So I got this to work:
...
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
this.passwordFile = config.getInitParameter( "passwordFile" );
this.passwords = new Properties();
passwords.load( config.getServletContext()
.getResourceAsStream( passwordFile ) );
} catch( IOException ioe ) {}
}
...
*But* this did not work, which I guess is a "relative issue":
...
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
this.passwordFile = config.getInitParameter( "passwordFile" );
this.passwords = new Properties();
passwords.load( new FileInputStream( passwordFile );
} catch( IOException ioe ) {}
}
...
Can someone summarize why the second example does not work with relative
paths? I understand why the first one does.
TIA
Tim
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org