Which one is better among <c:import> and <jsp:include> in terms of performance?

M.S.Naidu picture M.S.Naidu · Apr 23, 2013 · Viewed 41.1k times · Source

i am using import jstl tag, is it better to use jsp:include instead of import?

<c:choose>      
    <c:when test="${item.id=='masters'}">    
        <c:import url="/newclickmenu/mastermenuitems.jsp"></c:import>    
    </c:when>

    <c:when test="${item.id=='sales'}">   
        <c:import url="/newclickmenu/salesmenuitems.jsp"></c:import>   
    </c:when>
</c:choose>     

Answer

Pfft picture Pfft · Apr 23, 2013

<c:import> will offer a flexibility, and functionality improvement in addition to <jsp:include>.

  • <c:import> will allow you to specify content from other web applications, and contexts, as well as web servers; this gives you more flexibility.

  • Keep in mind though, that a static include, is always faster than a dynamic one; meaning that<%@ include file="" %> is faster than both <jsp:include> and <c:import>.

  • Technically, <c:import> should only be used if you require its functionality, or flexibility, the improvement in performance is minimal.

  • Some might state that implementing <c:import> is bad practice if you do not need it due to it being more heavy weight than <jsp:include>.