獲取當前的系統路徑以及將專案部署到Tomcat伺服器上
一,獲取當前的系統路徑,得到專案的名字 String path = request.getContextPath();
假如註釋掉String path = request.getContextPath();執行頁面就會報500錯誤。
先聲明後使用
<%
String path = request.getContextPath();
%>
<link rel="stylesheet" type="text/css" href="<%=path%>/producemanager/style/common.css"/>
<link rel="stylesheet" type="text/css" href="<%=path
<link rel="stylesheet" type="text/css" href="<%=path%>/producemanager/js/jquery-easyui-1.4.4/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/producemanager/js/jquery-easyui-1.4.4/themes/icon.css"/>
<script type="text/javascript" src="<%=path
<script type="text/javascript" src="<%=path%>/producemanager/js/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=path%>/producemanager/js/layer/layer.js"></script>
<script type="text/javascript">
var path = "<%=path
function refresh(){
/* window.location.reload();頁面實現跳轉和重新整理 */
window.location.reload();
}
</script>
<div class="slect-bnt"><a class="cui-back" href="<%=path%>/qjqk_cplx.jsp" onclick="search();"></a></div>
<a class="cui-back" href="<%=path%>/sczxPage.jsp" title="返回上一級">
<img src="<%=path%>/producemanager/style/img/backicon.png" /></a>
<a class="cui-back" href="#" onclick="refresh()" style="right:150px;"title="重新整理"><img src="<%=path%>/producemanager/style/img/refresh.png" /></a>
<iframe allowtransparency="true" scrolling="no" frameborder="0" style="height:400px; width:100%;" src="<%=path%>/producemanager/qjjh/qjzl.jsp"></iframe>
$.ajax({
url: path+"/qjjh/QJ_ajaxGetPiChan",
type: 'POST',
success: function(result){
addSearchBox(result);
/* layer.close(loadingLayer_pc); */
}
});
//新增的方法 傳參:產品型號
function opencpDetalT(value){
var url = path+'/producemanager/qjjh/threeTable.jsp?params='+encodeURI(encodeURI(value, 'UTF-8'), 'UTF-8');
//window.showModalDialog(url,window,"dialogWidth=900px;dialogHeight=410px;center:yes;status:no;scrollbars:auto");
showTable("各車間缺件種類明細",url);
}
function syncData(){
$.ajax({
url: "<%=path%>/qnjh/QNJH_syncData",
type: 'POST',
data: {'tableFunctionName':'T_SCXT_ERP_QJ','datasource':'scxt'},
success: function(result){
if (result == '0') {
alert('資料同步成功!');
location.href = location.href;
}
}
});
}
<a href="<%=request.getContextPath()%>/xxxx.jsp">中的request.getContextPath()應該是獲取當前的系統路徑,得到專案的名字,如果專案為根目錄,則得到一個"",即空的字條串;
如果專案為ProduceManager, <%=request.getContextPath()% >/ xxxx.jsp將得到ProduceManager/xxxx.jsp,伺服器端的路徑則會自動加上,
<a href="XXXX.jsp"> 應該就是指當前路徑下的這個xxx.jsp頁面
二,將專案部署到Tomcat伺服器上
當使用Tomcat作為Web伺服器,專案一般部署在Tomcat下的webapps的目錄下。具體來說主要用兩種部署的路徑:
一是將web專案中的webRoot下的檔案直接拷貝到webapps/ROOT下(刪除ROOT下的原有檔案);
另一中方法在Tomcat下的webapps中建立以專案名稱命名(當然也可以用其他的名稱)的資料夾,並將webRoot下的檔案直接拷貝到該資料夾下。
對於第一部署方法,request.getContextPath()的返回值為空(即:"",中間無空格,注意區分null)。
對於第二部署方法,其返回值為:/建立的資料夾的名稱。