JSP頁面的basePath路徑的問題

2021-06-28 18:37:11 字數 1047 閱讀 2273

利用myeclipse建立jsp頁面時會自動加上

html** 

<

string 

path

= request

.getcontextpath(); 

string 

basepath

= request

.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/"; 

%>

html** 

<base

href

="<%=basepath%>"

>

這說明在該頁面中的所有路徑都是於專案的webroot為相對路徑,如專案的webroot下的images/***.jpg,則在任何含有

html** 

<base

href

="<%=basepath%>"

>

的頁面中都是以images/***.jpg來訪問該。如webroot/jsp/first.jsp

在first.jsp中含有***.jpg應該為

而不是html** 

好處:1.不需要在頁面中以../或../../來回到上級或上上級目錄

2.都是相對於webroot目錄,實現了路徑的統一

在jsp頁面中加上basePath的路徑問題

jspmyeclipse 利用myeclipse建立jsp頁面時會自動加上 html string path request.getcontextpath string basepath request.getscheme request.getservername request.getserve...

jsp頁面的位址

1 是jsp取得絕對路徑的方法,等價於 也就是取出部署的應用程式名或者是當前的專案名稱 比如我的專案名稱是demo1在瀏覽器中輸入為 http localhost 8080 demo1 a.jsp 或取出來的就是 demo1,而 代表的含義就是http localhost 8080 故有時候專案中這...

jsp頁面的base標籤

我們在用ide工具生成jsp頁面時通常都包含下面的兩段 string path request.getcontextpath string basepath request.getscheme request.getservername request.getserverport path 它們絕對...