发布时间:2025-12-10 19:50:18 浏览次数:3
request.getContextPath()用法「终于解决」request.getContextPath()是在开发Web项目时,经常用到的方法,其作用是获取当前的系统路径。 当使用Tomcat作为Web服务器,项目一般部署在Tomcat下的webapps的目录下。具体来说主要用两种部署的路径: 一是将web项目中的webRoot下的文件直接拷贝到webapps/ROOT下(删除ROOT下的原有文件); 另一中方法
request.getContextPath()是在开发Web项目时,经常用到的方法,其作用是获取当前的系统路径。
getContextPath效果
<%
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
%>
path IS: /jspSmartUpLoad
basePath IS: http://yangm1203.oicp.net:8080/jspSmartUpLoad/
request.getScheme() IS: http
request.getServerName() IS: yangm1203.oicp.net
request.getServerPort() IS: 8080