jsp:include vs jsp include directive

In JSP technology you can include another page in two modes: using jsp:include tag:

<jsp:include page=”dir/file.jsp” flush=”true”/>

Or with the include file directive:

<%@ include file=”dir/file.jsp” %>

What’s the difference?

In the first case the page is called and compiled at run-time and in the second case is called and compiled at compiled-time.

I notice that a jsp file is re-compiled everytime it changes.

For example if you are using the inlcude directive and you modify the included page you still see the same previously compiled result. You need to recompile the father jsp in order to recompile the child jsp. In this case you need to change (or touch) the both.

Using the jsp:include it is not necessary because everytime the both jsp are re-compiled.

You say: “Ok, but I’m sure I’ll not change the included/child jsp”.

Perfect! Change the param flush to false.

Here you can find more jsp directives.