JSP EL 中 LENGTH[...] 和 fn:length(...) 之间的区别
LENGTH[...]
和 JSTL 函数 fn:length(...)
之间有什么区别?
我尝试搜索差异,但没有看到任何使用第一个示例的示例。
这是一个例子:
<c:when test="${object.field ne null || LENGTH[object.field] > 0}">
<td valign="top">
.....print something
</td>
</c:when>
What is the difference between the LENGTH[...]
and the JSTL function fn:length(...)
?
I tried to search to difference but I did not see any example that uses the first one.
Here is an example:
<c:when test="${object.field ne null || LENGTH[object.field] > 0}">
<td valign="top">
.....print something
</td>
</c:when>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于标准 JSP/JSTL/EL 中没有像
LENGTH[...]
这样的函数,因此无法区分其中的差异。fn:length()
是获取String
、Object[]
或Collection
长度的唯一方法。根据您的(固定)示例更新:
我以前从未见过此情况。您的 webapp/servletcontainer 似乎正在使用自定义 EL 解析器。如果这是真的,您应该会看到它已在 web 应用程序的
web.xml
文件中声明。无论如何,您宁愿在此处使用 EL
empty
关键字。它不仅检查null
,还检查String
、Object[]
或Collection
的长度。这里不需要
fn:length()
。大括号符号
[]
又通常用于通过动态键访问属性。例如,如果
propertyname
解析为“foo”,则上述内容实际上与${bean.foo}
相同。它也经常用于范围内的Map
对象。Since there is no such function like
LENGTH[...]
in standard JSP/JSTL/EL, it's impossible to tell about the differences. Thefn:length()
is the only way to obtain the length of aString
, anObject[]
orCollection
.Update as per your (fixed) example:
I've never seen this before. It look like that your webapp/servletcontainer is using a custom EL resolver. If this is true, you should see it been declared in webapp's
web.xml
file.Regardless, you'd rather like to use the EL
empty
keyword here. It not only checks fornull
, but also for the length of theString
,Object[]
orCollection
.No need for
fn:length()
here.The brace notation
[]
is in turn by the way often used to access properties by dynamic keys. E.g.If
propertyname
resolves to "foo", then the above does effectively the same as${bean.foo}
. It's also often used onMap
objects in the scope.