从request获取各种路径总结
request.getRealPath("url");//虚拟目录映射为实际目录
request.getRealPath("./");//网页所在的目录
request.getRealPath("../");//网页所在目录的上一层目录
request.getContextPath();//应用的web目录的名称
如http://localhost:7001/bookStore/
/bookStore/ => [contextPath] (request.getContextPath())
获取Web项目的全路径
String strDirPath = request.getSession().getServletContext().getRealPath("/");
request.getRealPath("url");//虚拟目录映射为实际目录
request.getRealPath("./");//网页所在的目录
request.getRealPath("../");//网页所在目录的上一层目录
request.getContextPath();//应用的web目录的名称
如http://localhost:7001/bookStore/
/bookStore/ => [contextPath] (request.getContextPath())
获取Web项目的全路径
String strDirPath = request.getSession().getServletContext().getRealPath("/");
本文总结了通过Java Servlet API中的request对象获取Web应用中不同路径的方法,包括如何将虚拟目录映射到实际目录,以及如何获取当前网页、上下文路径等。

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



