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 −
<html> <head> <title>The include Action Example</title> </head> <body> <center> <h2>The include action Example</h2> <jsp:include page = "date.jsp" flush = "true" /> </center> </body> </html>
Let us now keep all these files in the root directory and try to access main.jsp. You will receive the following output −
Today's date: 12-Sep-2010 14:54:22