關於的一點思考

在未定義<base href="<%=basePath%>">之前:

<a href="/index.jsp">註冊用戶</a> :實際URL:http://localhost:8080/index.jsp  顯然這是tomcat的初始頁面,這顯然不是我們想要的,相對於服務器的路徑

<a href="index.jsp">註冊用戶</a> :實際URL:http://localhost:8080/day24/my/name/index.jsp   /my/name爲當前頁面路徑  可以看出不加/即爲相對當前頁面下的路徑

在定義<base href="<%=basePath%>">後:

<a href="/index.jsp">註冊用戶</a> :實際URL:http://localhost:8080/index.jsp  任然是相對於服務器的路徑

<a href="index.jsp">註冊用戶</a> :實際URL:http://localhost:8080/day24/index.jsp   這纔是我們想要的路徑,相對於basePath的路徑

總結:

1.加入<base href="<%=basePath%>是爲<a href="index.jsp">起作用,這中寫法爲相對於base的相對路徑。

2.“/”爲虛擬路徑,爲服務器的路徑。

3.當前環境的寫法爲: href="/day24/index.jsp"。

繼續測試以下路徑:

在未定義<base href="<%=basePath%>">之前:

"./":代表目前所在的目錄。http://localhost:8080/day24/my/name/index.jsp

"../":代表上一層目錄。http://localhost:8080/day24/my/index.jsp

在定義<base href="<%=basePath%>">後:

"./":代表目前所在的目錄。http://localhost:8080/day24/index.jsp

"../":代表上一層目錄。http://localhost:8080/index.jsp

重點:分清相對路徑 與根路徑,相對路徑相對誰?!


href="index.jsp" href="./index.jsp" href="../index.jsp"均爲相對路徑,根據base的定義 相對的對象也有所不同
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章