您的位置:首页 > 其它

一个EL IF表达式引发的血案

2012-08-15 11:14 204 查看
废话不多说,先上问题.代码描述如下:

<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表达式的.

//  c:if
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);
_jspx_th_c_if_0.setPageContext(_jspx_page_context);
_jspx_th_c_if_0.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_c_forEach_1);
_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());
int _jspx_eval_c_if_0 = _jspx_th_c_if_0.doStartTag();
if (_jspx_eval_c_if_0 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
do {
out.write("\r\n");
out.write("\t\t\t\t执行部门任务\r\n");
out.write("\t\t\t");
int evalDoAfterBody = _jspx_th_c_if_0.doAfterBody();
if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)
break;
} while (true);
}


注意第五行的proprietaryEvaluate方法,它的参数是"${fn:trim(p.participanttype) eq 'dept' } " 最后包含一个空格,个人分析问题就出在这里.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: