今天做上传的时候,我想获取到web项目所在目录的路径,可以用下面的方法。
在java代码中:
String projectPath = ServletActionContext.getServletContext().getRealPath(""); //得到是D:\work_soft\apache-tomcat-7.0.47\webapps\webAppName
得到项目的父目录:
File projectFile = new File(projectPath); // 得到项目所在目录的父目录,D:\work_soft\apache-tomcat-7.0.47\webapps String imagePath = projectFile.getParent()
在javascript中获取主机的ip和端口号:
var path = window.location.host alert(path); //localhost:8080