BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Difference between include directive and include tag in JSP

By Chaitanya Singh | Filed Under: JSP tutorial

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:

include-directive-example

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.

include-action-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.

❮ JSP directives

JSP Tutorial

  • Basics of JSP
  • Life cycle of JSP
  • JSP in Eclipse IDE

Scripting Elements

  • Scriptlet Tag
  • Expression tag
  • Declaration tag

Implicit Objects

  • Implicit Objects
  • JSP Request
  • JSP Response
  • JSP Config
  • JSP Application
  • JSP Session
  • JSP Out
  • JSP pageContext
  • JSP Exception
  • Validate session

JSP directives

  • JSP Directives
  • Include Directive

JSP Exception

  • Exception handling

JSP Action

  • Action tags
  • Include action
  • Forward action
  • useBean, setProperty & getProperty

Expression language

  • Expression language

JSP Custom Tags

  • Custom Tags
  • Custom tag example
  • JSP Interview Q

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap