用JSP取得絕對路徑

來源:互聯網
上載者:User

標籤:path   style   conf   default   --   tle   logs   def   copy   

來自大神:http://www.cnblogs.com/xdp-gacl/p/3707243.html

在JavaWeb開發中,常使用絕對路徑的方式來引入JavaScript和CSS檔案,這樣可以避免因為目錄變動導致引入檔案找不到的情況,常用的做法如下:

一、使用${pageContext.request.contextPath}

  代碼” ${pageContext.request.contextPath}”的作用是取出部署的應用程式名稱,這樣不管如何部署,所用路徑都是正確的。

例如:

1 <!--使用絕對路徑的方式引入CSS檔案-->2 <link rel="stylesheet" href="${pageContext.request.contextPath}/themes/default/css/ueditor.css" type="text/css"/>3 <!--使用絕對路徑的方式引入JavaScript指令碼-->4 <script type="text/javascript" src="${pageContext.request.contextPath}/ueditor1_3_6-gbk-jsp/ueditor.config.js"></script>

使用<%=request.getContextPath()%>和使用${pageContext.request.contextPath}達到同樣的效果

<script type="text/javascript" src="<%=request.getContextPath()%>/ueditor1_3_6-gbk-jsp/ueditor.all.js"></script>  

用JSP取得絕對路徑

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.