Include directive and include action tag both are used for including a file to the current JSP page. However there is a difference in the way they include file. Before I explain the difference between them, let’s discuss them briefly.
JSP Include Directive
index.jsp
<html> <head> <title>JSP include Directive example</title> </head> <body> <%@ include file="display.jsp" %> </body> </html>
display.jsp
<p>This is the content of my file</p>
Output:
JSP Include Action tag
index.jsp
<html> <head> <title>JSP include Action example</title> </head> <body> <jsp:include page="display.jsp" /> </body> </html>
display.jsp
same as above example
Output: It is exactly same what we got in include directive example.
JSP include directive vs include action tag
We have seen above that the output got from both is same, however there are few noticeable differences among them.
1) Include directive includes the file at translation time (the phase of JSP life cycle where the JSP gets converted into the equivalent servlet) whereas the include action includes the file at runtime.
2) If the included file is changed but not the JSP which is including it then the changes will reflect only when we use include action tag. The changes will not reflect if you are using include directive as the JSP is not changed so it will not be translated (during this phase only the file gets included when using directive) for request processing and hence the changes will not reflect.
3) Syntax difference: Include directive: <%@ include file="file_name" %>
whereas include action has like this <jsp:include page="file_name" />
4) When using include action tag we can also pass the parameters to the included page by using param action tag but in case of include directive it’s not possible.
<jsp:include page="file_name" /> <jsp:param name="parameter_name" value="parameter_value" /> </jsp:include>
These are the major differences between include directive and include action.