1. Servlet
String path = getServletContext().getRealPath("/");
d:/workspace/project/
2.
getClass.getClassLoader().getResource("/").getPath();
d:/workspace/project/WEB-INF/classes/
3.
request.getContextPath();
/project (web项目的root context)
String path = request.getContextPath();
String scheme = request.getScheme();
String serverName = request.getServerName();
int port = request.getServerPort();
String basePath = scheme+"://"+serverName+":"+port+path+"/";
http://localhost:8080/project/
String path = getServletContext().getRealPath("/");
d:/workspace/project/
2.
getClass.getClassLoader().getResource("/").getPath();
d:/workspace/project/WEB-INF/classes/
3.
request.getContextPath();
/project (web项目的root context)
String path = request.getContextPath();
String scheme = request.getScheme();
String serverName = request.getServerName();
int port = request.getServerPort();
String basePath = scheme+"://"+serverName+":"+port+path+"/";
http://localhost:8080/project/