user3690467
user3690467

Reputation: 3417

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:

enter image description here

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

Upvotes: 4

Views: 4194

Answers (3)

Bobi John
Bobi John

Reputation: 1

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

Upvotes: 0

Siby
Siby

Reputation: 1

Try using:

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

Upvotes: -2

Emanuele Giona
Emanuele Giona

Reputation: 781

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"/>

Upvotes: 3

Related Questions