读书人

获取服务器的途径

发布时间: 2012-09-01 09:33:02 作者: rapoo

获取服务器的路径

1、 String contextPath = request.getContextPath(); String realPath = request.getSession().getServletContext().getRealPath("/"); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+contextPath+"/"; 2、 contextPath  = "/项目名称";  //获取的是项目的相对路径 realPath = F:\tomcat_home\webapps\项目名称\  //获取的是项目的绝对路径 basePath = http://localhost:8080/项目名称/   //获取的是服务的访问地址 

读书人网 >编程

热点推荐