2 Minutes To Code (β Version)

JSP - 2 minute tutorial

Include Directive - How to statically include source code of another webpage at compile time

to the jsp engine (webserver), unlike jsp actions (forward action & include action ) which are run-time instructions.

What include directive does it, it includes the source code of given jsp in the source code of the including jsp and then compiles this combined source code as a single servlet.

Let's check an example of include directive with landingPage.jsp and includedPage.jsp below.

Source code of landingPage.jsp


		Let's inlcude the output of another page.
		<%@ include file="includedPage.jsp" %>

</body> </html>

Source code of landingPage.jsp using xml tags


		Let's inlcude the output of another page.
		<jsp:directive.include file="includedPage.jsp" />

Source code of includedPage.jsp

	This text is from the included page
	Current date is <%= new java.util.Date() %>

Now, if you deploy landingPage.jsp and includedPage.jsp and point your browser to the landingPage.jsp, then the webpage shown below will be produced.

Notice the difference with jsp include action which process the included jsp at run time and includes only the resulting content in the output of the including jsp.

Also notice that the source code of includedPage.jsp does not have <html> or <body> tags as it is altready present in the landingPage.jsp.