Include directive vs Include Action

Include directive (<%@ include %>) includes file into the JSP page at compile time.

Include directive vs Include Action

     

Include directive: Include directive (<%@ include %>) includes file into the JSP page at compile time. Include directive should be used if the included code is in the same page.

Include Action: Includes action (<jsp:include>) includes the output at runtime. Include action (runtime include) runs a bit slower yet it is preferred generally because it save a lot of memory of the system. 

E.g: Suppose there are two pages welcome.jsp and index.jsp and welcome.jsp includes index.jsp, index.jsp is invoked only when welcome.jsp executes, and the output of index.jsp is inserted into the output stream of welcome.jsp. 

For example, if you want to use an include having a set of tag libraries with the taglib directive, you should use a compile-time include. If you wish to insert a standard header and footer in your page, include action will be more efficient.