首页 > Web开发 > 详细

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

时间:2017-11-07 12:01:10      阅读:265      评论:0      收藏:0      [点我收藏+]

 

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()%>】项目路径

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!