jsp中的js中獲取項目路徑的方法


在jsp中加上

 

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

 

然后在jsp中的其他地方都可以通過  <%=bathPath%> 的方式來引用

 


 在js中直接定義成變量使用:

<script>   $(function(){     var rootPath = "<%=bathPath%>"; alert(rootPath );   } </script>

注意:要有 等號:

       var rootPath = "<%=bathPath%>";

 

其他使用方式:

<!-- 在各種src/href中使用 -->
<script type="text/javascript" src="<%=path%>/js/echarts.js"></script>

<!-- 在隱藏域中使用 --> <input type="hidden" id="rootPath" value="<%=path%>">

<!-- 在a標簽中使用 --> <a href="<%=path%>/trend_downTrendReport.action?discussForm.id=${discussFrom.id}">導出報告按鈕</a>

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM