67,549
社区成员




HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
3、如果获取的是Tomcat的目录的话,可以考虑使用System.getProperty("user.dir")来获取Tomcat安装目录下的bin目录的绝对路径。
这个方法只是查看堆栈信息,是报错之后才加上去的。
public class Path {
public static String path_tomcat(){
new Exception().printStackTrace();
//return ServletActionContext.getServletContext().getRealPath("\\file\\userPhoto\\") + "\\";
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
System.out.println("servletContext:" + request.getServletContext());
String str = request.getServletContext().getRealPath("");
System.out.println("realpath:" + str);
System.out.println(Config.separator + Config.projectName);
str = str.substring(0,str.indexOf(Config.separator + Config.projectName));
return str;
}
public static void main(String[] args) {
String str = "D:\\apache-tomcat-7.0.59\\webapps\\manage";
str = str.substring(0,str.indexOf("\\manage"));
System.out.println(str);
}
}