In this post, I will help you understand the differences between JSP include action and JSP include directive.

You know, in JSP, there are two include mechanisms which look like they do the same thing:

<%@ include file="content.jsp" %>

And:

<jsp:include page="content.jsp" />

The former is called include directive and the latter is called include action. Both are used to include a resource into the current JSP page, which is useful for re-using common pages and code fragments across JSP pages such as header, footer, menu, category… of a web application.

However they behave differently, the following table summarizes the commons and differences of these two include mechanisms:

 

Content type

Include mechanism

Inclusion time

Page URL

Position-sensitive

Include directive

static

Source code of the included file.

at translation time

Relative URL.

Runtime expression not allowed.

Yes

Include action

static and dynamic

Response of the included page.

at request time

Relative URL.

Accept runtime expression

Yes

 

The include directive <%@include %>:

 

The include action <jsp:include>:

Related JSP Tutorials:

 

Other JSP Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.