一個EL IF表達式引發的血案


廢話不多說,先上問題.代碼描述如下:

 

<td class="td-b" width="10%">
  <c:if test="${fn:trim(p.participanttype) eq 'dept' } " >
      執行部門任務
    </c:if>
    <c:if test="${p.participanttype eq 'person'}" >
      執行個人任務
    </c:if>
 </td>

前提:各個變量的取值都是正確的.

問題:第一個if 打死都不執行....

問題分析:

  el表達式 ${fn:trim(p.participanttype) eq 'dept' }的輸出結果是ture.

  test的值是"ture ".注意這個地方多了一個空格....這就是罪魁禍首...大爺的

接下來看一下jsp對於的java文件 是如何解析el表達式的.

 1 //  c:if
 2     org.apache.taglibs.standard.tag.rt.core.IfTag _jspx_th_c_if_0 = (org.apache.taglibs.standard.tag.rt.core.IfTag) _jspx_tagPool_c_if_test.get(org.apache.taglibs.standard.tag.rt.core.IfTag.class);
 3     _jspx_th_c_if_0.setPageContext(_jspx_page_context);
 4     _jspx_th_c_if_0.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_c_forEach_1);
 5     _jspx_th_c_if_0.setTest(((java.lang.Boolean) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${fn:trim(p.participanttype) eq 'dept' } ", java.lang.Boolean.class, (PageContext)_jspx_page_context, _jspx_fnmap_0, false)).booleanValue());
 6     int _jspx_eval_c_if_0 = _jspx_th_c_if_0.doStartTag();
 7     if (_jspx_eval_c_if_0 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
 8       do {
 9         out.write("\r\n");
10         out.write("\t\t\t\t執行部門任務\r\n");
11         out.write("\t\t\t");
12         int evalDoAfterBody = _jspx_th_c_if_0.doAfterBody();
13         if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)
14           break;
15       } while (true);
16     }

注意第五行的proprietaryEvaluate方法,它的參數是"${fn:trim(p.participanttype) eq 'dept' } " 最后包含一個空格,個人分析問題就出在這里.

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM