Calling EL function with EL variable like ${fn:toLowerCase(${Person.name})} doesn't work

跟風遠走 提交于 2019-12-02 12:45:22

问题


I am passing a bean: Person to my jsp page, and I would like to print his name in lower case. To do this, I'm calling jstl's function toLowerCase, but this doesn't work:

<c:out value="${fn:toLowerCase(${Person.name})}"

Instead, I have to set the variable

<c:set var="personName" value="${Person.name}"/>
<c:out value="${fn:toLowerCase(personName)}"

Is there a more syntactically friendly way of doing this?


回答1:


Nesting EL expressions is illegal syntax. That should also have been hinted in some way by the exception which you faced but didn't tell anything about. You should see the EL expression ${... ...} as one big global scope wherein various EL scoped variables and functions can interact with each other. Your second attempt is doing it correctly. Just apply the same on the initial attempt:

<c:out value="${fn:toLowerCase(Person.name)}"/>

By the way, I'd rather respect Java naming conventoins and lowercase instance variable name Person to person. You also don't do Person Person = new Person(); in normal Java code, right?



来源:https://stackoverflow.com/questions/19292303/calling-el-function-with-el-variable-like-fntolowercaseperson-name-does

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