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>
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.
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).
The jsp:include action tag is used to include the content of another resource it may be jsp, html or servlet.
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.
<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>
.
One important advantage of c:import is that it can include the external resources like other web application from the current context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With