Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jsp

jstl

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>     
like image 887
M.S.Naidu Avatar asked Apr 23 '13 12:04

M.S.Naidu


People also ask

What is the difference between import and include in JSP?

The key difference between include action and JSTL import tag is that the former can only include local resources but later can also include the output of remote resources, JSP pages, or HTML pages outside the web container. include action uses page attribute while import tag uses URL attribute.

What does <% include do in JSP?

The include directive is used to include the contents of any resource it may be jsp file, html file or text file. The include directive includes the original content of the included resource at page translation time (the jsp page is translated only once so it will be better to include static resource).

Which of the following option helps to include a html or JSP file into another?

The jsp:include action tag is used to include the content of another resource it may be jsp, html or servlet.

What is the difference between JSP and tag file?

A tag file is a source file that contains a fragment of JSP code that is reusable as a custom tag. Tag files allow you to create custom tags using JSP syntax. Just as a JSP page gets translated into a servlet class and then compiled, a tag file gets translated into a tag handler and then compiled.


2 Answers

<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>.

like image 123
Pfft Avatar answered Nov 27 '22 05:11

Pfft


One important advantage of c:import is that it can include the external resources like other web application from the current context.

like image 29
Krishna Avatar answered Nov 27 '22 05:11

Krishna