在未定義<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
重點:分清相對路徑 與根路徑,相對路徑相對誰?!