簡體   English   中英

JSP - 包含資源文件夾中的文件

[英]JSP - Include a file from the resources folder

如何從資源路徑將文件包含到我的 jsp 文件中? 路徑具體應該是什么。 使用@includejsp:include

我的目錄結構:

在此處輸入圖片說明

我想包含resources/static/template/index.html應該是home.jsp的包含路徑。

您不應該在WEB-INF任何子目錄中包含 .jsp 文件,並且如果webapp是您的 Web 應用程序的上下文根,則您無法在其之外包含任何內容,因為 include 指令和標准標記都僅適用於文件在上下文根下。

如果您要將整個resources目錄移動到webapp下,那么您將能夠使用以下方法之一:

<%@include file="/resources/static/template/index.html"%>

或者

<jsp:include page="/resources/static/template/index.html"/>

我已經這樣解決了

  • 將 .html 等靜態文件從 src/main/resources/static/ 移動到 src/main/webapp/includes/。 例如,我在這里有我的 header.html 和 footer.html。
  • 要包含 .html 文件,請使用 <%@include file="????.html" %>
  • 要包含 .jsp 文件,請使用 <jsp:include page="????.jsp"/>
  • 替換??? 與文件的相對路徑

嘗試使用:

<%@include file="../../resources/static/template/index.html" %>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM