Example & Tutorial understanding programming in easy ways.

what is the Difference between include directive and include action in JSP

include directive is <%@ include file="login.jsp" %> and include action in JSP is <jsp:include page="login.jsp" %>

Include directive and include action tag both are used for including a file to the current JSP page. Before I explain the difference between them, let’s have a brief about each one.

JSP Include Directive:

login.jsp

<html>

<head>

<title>this is JSP include Directive example</title>

</head>

<body>

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

</body>

</html>

JSP Include action:

<html>

<head>

<title>this is JSP include Action example</title>

</head>

<body>

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

</body>

</html>

output from the above both file is same, so we discuss here some diffrences.

Following are some common differences between include action and include directive in JSP:

1. include directive is static import while include action is dynamic import

2. Resource included by include directive is loaded during jsp translation time while resource included by include action is loaded during request time.
3. Any change on included resource will not be visible in case of include directive until jsp file compiles
again. While in case of include again any change in included resource will be visible in next request.

4. include directive uses file attribute to specify resource to be included while include action use page attribute for same purpose.

5. Another difference JSP include action can be dynamic and request time expression and you can also pass parameter to the file which you are going to include using include action e.g.

<jsp:include page="login.jsp">

<jsp:param name="some" value="pass"/>

Read More →