EL vs. JSTL in JSP pages
I recently had a chance to examine the difference between using JSTL tags and Expression Language (EL) in outputting content in JSPs.
For these two lines of JSP code that output the same content:
<body><c:out value="${header['host']}"/></body> // JSTL
and
<body>${header["host"]}</body> // EL
the following diff obtains in the generated JSP Java source code:
bmac:jstlvsel> diff --suppress-common-lines -y jstl_jsp.java el_jsp.java
private org.apache.jasper.runtime.TagHandlerPool _005fjspx_ <
<
_005fjspx_005ftagPool_005fc_005fout_0026_005fvalue_005fno <
_005fjspx_005ftagPool_005fc_005fout_0026_005fvalue_005fno <
if (_jspx_meth_c_005fout_005f0(_jspx_page_context)) | out.write((java.lang.String) org.apache.jasper.runtime.
return; <
<
private boolean _jspx_meth_c_005fout_005f0(javax.servlet.js <
throws java.lang.Throwable { <
javax.servlet.jsp.PageContext pageContext = _jspx_page_co <
javax.servlet.jsp.JspWriter out = _jspx_page_context.getO <
// c:out <
org.apache.taglibs.standard.tag.rt.core.OutTag _jspx_th_c <
_jspx_th_c_005fout_005f0.setPageContext(_jspx_page_contex <
_jspx_th_c_005fout_005f0.setParent(null); <
// /out.jsp(4,6) name = value type = null reqTime = true <
_jspx_th_c_005fout_005f0.setValue((java.lang.Object) org. <
int _jspx_eval_c_005fout_005f0 = _jspx_th_c_005fout_005f0 <
if (_jspx_th_c_005fout_005f0.doEndTag() == javax.servlet. <
_005fjspx_005ftagPool_005fc_005fout_0026_005fvalue_005f <
return true; <
} <
_005fjspx_005ftagPool_005fc_005fout_0026_005fvalue_005fno <
return false; <
}
where the first file is the JSTL version and the second file the EL version.
As one can see, the JSTL version traverses the JSTL tag handling layer before output, while EL goes straight to output. It’s no secret that EL is more efficient for simple output tasks, but it’s always good to see why.
Advertisement