码迷,mamicode.com
首页 > Web开发 > 详细

jsp中【<%=request.getContextPath()%>】项目路径

时间:2017-11-07 12:14:47      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:nta   dex   sep   pad   body   png   server   etc   code   

 

1
2
"request.getContextPath()的值是        "<%=request.getContextPath()%><br/>
"pageContext.request.contextPath的值是   "${pageContext.request.contextPath}<br/>

  技术分享

通过运行我们发现了<%=request.getContextPath()%>和${pageContext.request.contextPath}获取的结果都是项目名(上下文),没有获取到项目的端口号

如果我们想要获取项目的绝对路径和端口号我们有什么办法呢

  

<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

通过运行结果可知<%=basePath%>可知结果是

  技术分享

 完整的路径和端口号还有项目的上下文环境。

结论:项目中用<%=basePath%>来指定项目的绝对路径,可解决因为修改服务器端口号引起的找不到路径问题。

 

jsp中【<%=request.getContextPath()%>】项目路径

标签:nta   dex   sep   pad   body   png   server   etc   code   

原文地址:http://www.cnblogs.com/tijun/p/7798189.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!