radioAe6rt

EL vs. JSTL in JSP pages

leave a comment »

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

Written by radioae6rt

June 29, 2011 at 6:04 am

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.