在类和JSP中获取当前WEB应用的路径

来源:互联网 发布:天天助手计划软件 编辑:程序博客网 时间:2024/05/21 07:49

这个总要查,所以记录一下,下面的代码是获取到当前应用的目录

在类文件中:   

String path = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();path = path.substring(0, path.indexOf("WEB-INF"));jsonFile=new File(path+"\\content\\a.jsp");

在JSP中:

InputStream is=null;String path = application.getRealPath("/");is=new FileInputStream(path+"\\WEB-INF\\conf\\config.properties");



原创粉丝点击