6

How do I include a JSP file from a different project into my project?

<%@ include file="./common/webappfooter.jsp"%>

The above code does not work.

Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
user1472384
  • 93
  • 3
  • 8

1 Answers1

12

This works only if the other project is bundled in flavor of a JAR file in /WEB-INF/lib folder of the main webapp project and if the JSP file is in turn placed in /META-INF/resources folder of the other project.

So, if you have a /META-INF/resources/common/webappfooter.jsp in the other project, then the following include should do:

<jsp:include path="/common/webappfooter.jsp" />

If you're using a bit self-respected IDE, you can configure it to automatically bundle the other project as JAR of webapp project's /WEB-INF/lib. It's unclear what IDE you're using, but in Eclipse it's a matter of adding the other project as Deployment Assembly in the main webapp project's properties.

alt text

In Eclipse, to create such a project with the right folder structure prepared, choose the "Web Fragment Project" wizard.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555