Java EE >> JSP >> Web Applications


Difference between JSP include directive and JSP include action


There are two ways in which the output of one JSP can be included into another JSP. These include the static and dynamic including. Static include can be done by using JSP include directive and dynamic include can be done by using the JSP include action.

The output of one JSP can be included into another by uisng any of the above described methods. But there are different scenarios where each one of them should be used.

JSP Static Include

JSP static include can be done by using the include directive as shown below:

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

The effect of above statement will be to include the test.jsp contents into the parent JSP page while the parent JSP is being compiled into a Java class. Thus if any changes are done in test.jsp, they will not get reflected in parent JSP page until the parent JSP is not re-compiled.

JSP Dynamic Include

JSP dynamic include can be done by using the JSP include standard action which involves executing the included JSP and adding the response received from included JSP to the parent JSP on the fly.

The following code snippet shows how dynamic inclusion of JSP can be done:

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

In the above JSP code snippet, any changes done in test.jsp are instantly reflected in the parent jsp page when a request is sent to parent jsp. This is because the contents of child jsp are included in parent only when a request for parent jsp is received.

Java EE Tutorials
Struts Interview Questions after 5 years
Distributed Cache tools for Java Applications
Caching Data in Java Applications

Leave Comment