1
我想包括一個jsp頁面在另一個,因爲我不想硬編碼路徑我想要使用request.getContextPath()方法。 但我不能得到它的工作。我已經試過各種事情,基於不同的答案在這裏:JSP包含頁面失敗request.getContextPath()
我所做的第一件事就是
<jsp:include page="<%=request.getContextPath()%>/structure/Navbar.jsp" />
給我:
HTTP Status 500 - /structure/ArtiMarziali/Aikido.jsp (line: 11, column: 24) attribute value for [page] is not properly terminated
所以,我想:
<% String aikido = request.getContextPath() + "/structure/Navbar.jsp"; %>
<jsp:include page="<%= aikido %>" />
拋出異常:
HTTP Status 500 - javax.servlet.ServletException: File [/ProgettoPW/structure/Navbar.jsp] not found
然後:
<jsp:include page="<%= request.getContextPath() + "/structure/Navbar.jsp" %>" />
說我需要轉義引號,我不能真正做到
和
<jsp:include page='<%= request.getContextPath() + "/structure/Navbar.jsp" %>' />
給出了同樣的錯誤作爲第一個。我嘗試將getContextPath的結果設置爲變量並在標記中使用該變量,但是與以前相同的錯誤。
我真的不知道我有什麼問題,我需要一些幫助,謝謝。
(是的,我知道,使用<%=%>和其他小腳本是在時下皺起了眉頭,但我的課程講授這種方式,我想堅持下去的項目)
編輯:這是文件結構,可能是有用的:
你試過簡單的' '? –
是的,它的工作原理,但我真的不明白爲什麼它如果我這樣做,但不與getContextPath()。鏈接的CSS文件和圖像適用於它,但不包括jsp包括。 (正如我所說,我不想使用硬編碼的路徑,以防我動起來) – Paul
它的工作原理是因爲路徑已經相對於上下文路徑,所以希望我們不需要添加它 –