java获取web项目下文件夹的路径方法

方法一:

String realPath=request.getSession().getServletContext()
.getRealPath("upload");

方法二:

WebApplicationContext webApplicationContext = ContextLoader
.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext
.getServletContext();
// 得到文件夹绝对路径
String realPath = servletContext.getRealPath("upload");

猜你喜欢

转载自www.cnblogs.com/penghq/p/9553039.html
今日推荐