The jsp:include action tag is made in use to comprise the content of some other resource; it may be jsp, HTML, or servlet.
The jsp contains action tag comprises the resource at request time so it is better for dynamic pages because they can be substituted in the future.
The jsp:include a tag that might be used to comprise static and side-by-side dynamic pages.
Code reusability: We can make use of a page many times like including header and footer pages on all pages. So it saves a lot of time.
JSP include directive | JSP include action |
Comprise resources at translation time. | comprise resources at request time. |
Good for static pages. | good for dynamic pages. |
Comprise the original content in the produced servlet. | calls the include method. |
<jsp:include page="relativeURL ' <%= expression %>" />
<jsp:include page="relativeURL ' <%= expression %>"> <jsp:param name="parametername" value="parametervalue ' <%=expression%>" /> </jsp:include>
In the below given example, The index.jsp file comprises the content of the printdate.jsp file.
File:index.jsp
<h2>this is index page</h2> <jsp:include page="printdate.jsp" /> <h2>end section of index page</h2>
File:printdate.jsp
<% out.print("Today is:"+java.util.Calendar.getInstance().getTime()); %>