getServletContext().getRealPath("/")

来源:互联网 发布:ubuntu安装qt5 编辑:程序博客网 时间:2024/05/01 11:43
request.getSession().getServletContext() 获取的是Servlet容器对象,相当于tomcat容器了.getRealPath("/") 获取实际路径,“/”指代项目根目录,所以代码返回的是项目在容器中的实际发布运行的根路径。如:D:\apachetomcat6.0.32\webapps\cloudOABaseV4\hwtt_uploadPS:文件分隔符(在 UNIX 系统中是“/”),window 是"\" Window:   D:\apache-tomcat-6.0.32\webappsLinux:   ​D:/apache-tomcat-6.0.32/webapps故文件上传时,若服务器是linux系统,需进行分隔符转换。​this.savePath = this.savePath.replace("\\", "/");
0 1