預設 Tomcat 應用訪問路徑為 https://localhost:8080/項目名/。若需直接用 https://localhost:8080/ 訪問,需將該項目部署為 ROOT 應用。
<Host name="localhost" appBase="webapps" ...>
<Context path="" docBase="你的項目名" debug="0" reloadable="true"/>
</Host>
path="" 表示根上下文 (無前綴)。docBase 指向項目目錄 (相對 appBase 或絕對路徑)。webapps/ROOT 目錄 (默認歡迎頁) 避免衝突。你的項目.war 重命名為 ROOT.war。webapps/,刪除舊 ROOT 目錄。/ (空字符串或 /)。server.xml 的 <Context> 中設定 path="/"。重啟 Tomcat,訪問 https://localhost:8080/ 直接進入應用首頁。
path="" 應用。request.getContextPath()) 將返回空字符串,拼接 URL 時需注意:response.encodeURL(request.getContextPath() + "/xxx")。<c:url value="/css/main.css"/>。配置 path="" 即可移除上下文路徑前綴。