request.getSession().getServletContext().getRealPath("") + "*********1******"request.getSession().getServletContext().getRealPath("config") + "********2*******"Thread.currentThread().getContextClassLoader().getResource("") + "***********3****"Thread.currentThread().getContextClassLoader().getResource("config") + "********4*******");E:\kaiFa\IDEATest\desktop\classes\artifacts\desktop_war_exploded*********1******E:\kaiFa\IDEATest\desktop\classes\artifacts\desktop_war_exploded\config********2*******file:/E:/kaiFa/IDEATest/desktop/classes/artifacts/desktop_war_exploded/WEB-INF/classes/***********3****file:/E:/kaiFa/IDEATest/desktop/classes/artifacts/desktop_war_exploded/WEB-INF/classes/config/********4*******
路径获取对比:由上可以看出,
request.getSession().getServletContext().getRealPath("")获取到的是路径是应用的部署路径 ,并且如果即使不存在该路径,也会构建,就如原本目录没有config这个文件夹
Thread.currentThread().getContextClassLoader().getResource("")获取到是路径是web-inf下的classes路径
综合来说,request.getSession().getServletContext().getRealPath("")用于获取web-app下的资源文件
Thread.currentThread().getContextClassLoader().getResource("")用于获取maven中resource目录下文件。