Java Web项目开发中常见路径获取方法

项目绝对路径

String serverPath = request.getSession().getServletContext().getRealPath("/");


E:\JAVA\server\tomcat\apache-tomcat-7.0.77\webapps\lawreg\


项目根目录名称
String contextPath = request.getContextPath();  

 
/lawreg


服务器地址
String basePath = request.getScheme()+"://"+request.getServerName()+":"+
                request.getServerPort();


http://127.0.0.1:8080/


项目服务器地址路径
String basePath = request.getScheme()+"://"+request.getServerName()+":"+
                request.getServerPort()+contextPath+"/";


http://127.0.0.1:8080/lawreg/

posted @ 2017-12-05 14:06  卡洛斯利伯  阅读(315)  评论(0编辑  收藏  举报