js和jsp取得项目根路径的方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mingliangniwo/article/details/45842437

一.js
a.'${pageContext.request.contextPath}'//结果:/projectName
b.'<%=request.getContextPath()%>'//结果:/projectName
用法:
<script>
function searchData(dom){
   $(dom).attr('disabled', true);
   var url = '${pageContext.request.contextPath}/OrderController/getOrders.mmx?'+$('#orderForm').serialize();
   var url = '<%=request.getContextPath()%>'+'/OrderController/getOrders.mmx?'+$('#orderForm').serialize();
   $('#dataDiv').html('数据加载中...').load(url, function(){
      $(dom).attr('disabled', false);
   });
}
<script>
二.jsp
a.<%=request.getContextPath()%>//结果:/projectName
b.${pageContext.request.contextPath}//结果:/projectName
用法:
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/order/css/OrderCss.css" /> 
<link rel="stylesheet" type="text/css" href=<%=request.getContextPath()%>+"/order/css/OrderCss.css" /> 


展开阅读全文

没有更多推荐了,返回首页