在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>
