简体   繁体   中英

JSP - Include a file from the resources folder

How do I include a file into my jsp file from the resources path? What should the path be specifically. Using either @include or jsp:include .

My directory structure:

在此处输入图片说明

I want to include resources/static/template/index.html what should be the include path in home.jsp .

You shouldn't have .jsp files in any subdirectory of WEB-INF , and if webapp is the context root of your web application, there's no way you can include anything outside it, since both the include directive and standard tag only work on files under the context root.

If you were to move the whole resources directory under webapp , then you'll be able to use one of the following:

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

Or

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

I have solved it like this

  • Move the static files like .html from src/main/resources/static/ to src/main/webapp/includes/. eg I have my header.html and footer.html here.
  • To include .html file, use <%@include file="????.html" %>
  • To include .jsp file, use <jsp:include page="????.jsp"/>
  • Replace ???? with the relative path of the file

尝试使用:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM