1 Reply Latest reply on Jul 26, 2003 9:25 PM by Jon Barnett

    Servlet reading files from WEB-INF directory

    Harri Lehtimaki Newbie


      i'm using jboss-3.2.1_tomcat-4.1.24 and in one of my servlets i would need to read a template wml-file from the /WEB-INF directory.

      i have tried getServletContext( ).getRealPath( ), but it always seems to return null.

      this must be something trivial, but i've already spent one day trying to solve this.

      so, if anyone could give me a hint of how to read files in a jboss/tomcat servlet, i would be very happy.

      thanks in advance,

        • 1. Re: Servlet reading files from WEB-INF directory
          Jon Barnett Master

          The JBoss-Tomcat combination does not expand the WAR file. Under these conditions, the getRealPath() method will return a null. This is within spec and caters for any situation where the deployment does not exist locally or where the individual files do not physically reside on local storage media (it is still packaged, or in a DB or otherwise accessed from a remote location).

          You can use ServletContext.getResourceAsStream("/WEB-INF/MyFile.xml"). I think that is the correct style string but you need to experiment with this as it has been a long while since I did this and it was on SilverStream at the time, I think.