JSP - Include a file from the resources folder

Viewed 3162

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:

enter image description here

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

3 Answers

I have solved it like this

  • Move the static files like .html from src/main/resources/static/ to src/main/webapp/includes/. e.g. 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
Related