<c:if> not working for comparing characters [duplicate]

限于喜欢 提交于 2019-12-08 18:56:58

问题


<c:if> is not working for comparing characters.The code is inside a table.Here is the code

<c:if test="${record.type eq 'U' }">Planned</c:if>

When I use this code inside the table,the table content is not displayed.Please help!


回答1:


Issue is EL supports both double and single quoted Strings. So 'U' is taken as String, not char. To resolve the issue, you can use charAt(0) method on that String:

<c:if test="${record.type eq 'U'.charAt(0) }">Planned</c:if>



回答2:


check the value of ${record.type} print it on jsp

becuse

<c:if test="${'U' eq 'U'}">demo</c:if> 

it works for me in jsp

or if you have some version conflict then

try below one it may help

<c:if test = "${record.type == 'U'}">demo</c:if> 

but make sure the value of ${record.type}




回答3:


This works for me:

`<c:if test="${'U'.toString() eq 'U'}">demo</c:if>`

It works for me since instead of first 'U', I was getting the list of Characters. So the type should be converted to String first.)



来源:https://stackoverflow.com/questions/25498223/cif-not-working-for-comparing-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!