What is the function of <jsp:include> action in JSP?

JSPJava 8Object Oriented ProgrammingProgramming

This action lets you insert files into the page being generated. The syntax looks like this −

<jsp:include page = "relative URL" flush = "true" />

Unlike the include directive, which inserts the file at the time the JSP page is translated into a servlet, this action inserts the file at the time the page is requested.

Following table lists out the attributes associated with the include action −

S.No.Attribute & Description
The relative URL of the page to be included.
The boolean attribute determines whether the included resource has its buffer flushed before it is included.


Let us define the following two files (a)date.jsp and (b) main.jsp as follows −

Following is the content of the date.jsp file −

<p>Today's date: <%= (new java.util.Date()).toLocaleString()%></p>

Following is the content of the main.jsp file −

      <title>The include Action Example</title>
         <h2>The include action Example</h2>
         <jsp:include page = "date.jsp" flush = "true" />

Let us now keep all these files in the root directory and try to access main.jsp. You will receive the following output −

The include action Example

Today's date: 12-Sep-2010 14:54:22
Published on 20-Mar-2019 10:28:32