HttpServletRequest request = ServletActionContext.getRequest();
String pathString = request.getServletContext().getRealPath("/");
本文介绍了一种在Java Web应用中通过HttpServletRequest对象获取项目根目录绝对路径的方法。使用ServletActionContext.getRequest()获取请求对象,然后调用getServletContext().getRealPath(/)来得到项目的实际路径。
HttpServletRequest request = ServletActionContext.getRequest();
String pathString = request.getServletContext().getRealPath("/");
3663

被折叠的 条评论
为什么被折叠?