# 路徑問題 ###### tags: `Java Web-Servlet` ![](https://i.imgur.com/KxzvK3n.png) <font color="red">紅字:相對路徑</font> ../../css/login.css <font color="blue">藍字:絕對路徑</font> http://locahost:8080/pr010/css/index.css (IP地址:端口號/contextroot/css/index.css) ![](https://i.imgur.com/f7FhJh7.png) ```htmlmixed= <!-- ../css:回到此檔案的上一級(user),並且在到同級別的css資料夾 --> <!--相對路徑 --> <link href="../css/login.css" rel="stylesheet"> ``` ![](https://i.imgur.com/UamGKpY.png) ### 為了容易理解,盡量使用"絕對路徑" ====================================== <base href="http://localhost:8080/pr010/"/> 的作用是讓當前頁面的路徑都以這個為基礎 <link href="css/shoppong.css"> 就等於<link href="http://localhost:8080/pr010/css/shoppong.css"> ### 可以用thymeleaf應用 th:href="@{}" @{}等同於<base href="http://localhost:8080/pr010/"/> 因此<link th:href="@{/css/shoppong.css}"> 相當於<link href="http://localhost:8080/pr010/css/shoppong.css">