Get the WEB-INF folder path

This is a simple example on how to get the WEB-INF directory path in a J2EE web application.

public class MyClassName{
 
  private static final String WEBINF = "WEB-INF";
 
  public String getWebInfPath(){
 
    String filePath = "";
 
    URL url = MyClassName.class.getResource("MyClassName.class");
    String className = url.getFile();
 
    filePath = className.substring(0,className.indexOf(WEBINF) + WEBINF.length());
    return filePath;
  }
 
}

3 Responses

  1. KrisBelucci2.06.09 @ 12.06

    Hi, good post. I have been wondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.

  2. Leonardo • 21.03.10 @ 20.03

    Thanks! really helpfull

  3. cumi2 • 4.06.10 @ 05.06

    Simple but very helpfull, thanks Melandri

Leave a Reply