Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jsp

servlets

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.

like image 544
user1472384 Avatar asked Jun 26 '12 15:06

user1472384


People also ask

How do I import one JSP file to another?

To include JSP in another JSP file, we will use <jsp:include /> tag. It has a attribute page which contains name of the JSP file.

Is used to include a file in JSP?

Which of the following action variable is used to include a file in JSP? Explanation: jsp:include action variable is used to include a file in JSP.


1 Answers

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.

like image 187
BalusC Avatar answered Oct 06 '22 01:10

BalusC