JSP - 包含资源文件夹中的文件

JSP - Include a file from the resources folder

如何将资源路径中的文件包含到我的 jsp 文件中?具体路径应该是什么。使用 @includejsp:include.

我的目录结构:

我想包含 resources/static/template/index.html home.jsp 中的包含路径应​​该是什么。

尝试使用:

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

您不应该在 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 文件,请使用
  • 替换????与文件的相对路径