在WEB项目中如何获得根目录

2025-01-01 01:57:16
推荐回答(4个)
回答1:

Do you mean the project root Name?if so:
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
//out.print(basePath); //test
And this is automatic by MyEclipse

回答2:

直接给你发代码呢!!O(∩_∩)O~

package dao;

import java.io.File;
public class uu {
public static void main(String[] args){
File[] roots = File.listRoots();
for (int i=0; i System.out.println(roots[i]);
}
}
}

回答3:

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

这两个有一个 那个我网了自己 试一下吧

回答4:

request.getRealPath("/");