Fork me on GitHub

Programming Design Notes

動態地取得 WEB-INF 的位置

| Comments

動態地取得 WEB-INF 的位置:

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;
}

}

轉自: http://www.melandri.net/2009/05/28/get-the-web-inf-folder-path/

相關書籍: Beginning Java™ EE 6 Platform with GlassFish™ 3: From Novice to ProfessionalThe Java EE 6 Tutorial: Basic Concepts (4th Edition) (Java Series)Real World Java EE Patterns Rethinking Best Practices