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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to