JSP: Include Action Tag


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.

Benefits of Jsp:include Action Tag

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.

Differentiation Between JSP Include Directive and Include Action

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.

Syntax of Jsp:include Action Tag without Parameter

<jsp:include page="relativeURL ' <%= expression %>" />  

Syntax of jsp:include Action Tag with Parameter

<jsp:include page="relativeURL ' <%= expression %>">  
<jsp:param name="parametername" value="parametervalue ' <%=expression%>" />  

Example of jsp:include Action Tag without Parameter

In the below given example, The index.jsp file comprises the content of the printdate.jsp file.


<h2>this is index page</h2>  
<jsp:include page="printdate.jsp" />  
<h2>end section of index page</h2> 


<% out.print("Today is:"+java.util.Calendar.getInstance().getTime()); %>

download this example