使用$ {fn:toLowerCase($ {Person.name})}之类的EL变量调用EL函数不起作用 [英] Calling EL function with EL variable like ${fn:toLowerCase(${Person.name})} doesn't work

查看:87
本文介绍了使用$ {fn:toLowerCase($ {Person.name})}之类的EL变量调用EL函数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个bean:Person传递到我的jsp页面,并且我想用小写字母打印他的名字.为此,我正在调用jstl的函数toLowerCase,但这不起作用:

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})}"

相反,我必须设置变量

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

是否有一种语法上更友好的方式做到这一点?

Is there a more syntactically friendly way of doing this?

推荐答案

嵌套EL表达式是非法语法.您所遇到的异常也没有以某种方式暗示了这一点,但没有透露任何内容.您应该将EL表达式${... ...}视为一个大的全局范围,其中各种EL范围的变量和函数可以相互交互.您的第二次尝试是正确执行.只需在初始尝试中应用相同的内容即可:

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)}"/>

顺便说一句,我宁愿尊重 Java将conventoins 和小写实例变量名称Person命名为person.您也不用普通的Java代码执行Person Person = new Person();,对吗?

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?

这篇关于使用$ {fn:toLowerCase($ {Person.name})}之类的EL变量调用EL函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆