jsp中獲取頁面的相對路徑
阿新 • • 發佈:2017-08-11
ets sch true 獲取 當前頁 rpo scrip class head
1.在jsp頁面的上方加上這段java代碼
<%
// request.getContextPath() 返回當前頁面所在的應用的名字;
// request.getSchema() 返回當前頁面使用的協議,如:http;
// request.getServerName() 返回當前頁面所在的服務器的名字;
// request.getServerPort() 返回當前頁面所在的服務器使用的端口 String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %>
2.在jsp頁面的<head></head>下加上這段代碼
<head> <base href="<%=basePath%>"> <script src="js/jquery-1.9.1.js"></script> </head>
這樣就可以了
jsp中獲取頁面的相對路徑