What are the differences between including another file in JSp using <jsp:include file= "foo.jsp" /> and <%@ import page= "foo.jsp" %>? Are both methods same? If they are same why there are 2 ways to include another file? If different what are the adv and disadv of each method? Regards, -Parsu.
<%@ include file="filePath"%> include directive is used to include STATIC files at TRANSLATION time which will be PARSED by JSP Engine. <jsp:include page="pageURI"/> include action is used to include STATIC / DYNAMIC files at REQUEST PROCESSING time which will NOT be PARSED by JSP Engine.
To throw some extra light. Both Static (<%@ include file="filePath"%> ) and dynamic<jsp:include page="pageURI"/> include are there for code reusability. Static Include includes pages at translation time and dynamic Include includes pages at run time. Dynamic Include is lot more flexible than the Static at some extra performance cost, as the pages are included at runtime. For example when you are using Container/Component model like one Page acts as container and other pages act as components. The Dynamic includes gives lot flexibility to make run time decision like what are the components(pages) to include and the ones to omit. This is not possible when we use Static include as all the pages are included at the translation phase and compiled as one unit.