表达式语言中的调用方法 [英] Call methods in Expression Language

查看:94
本文介绍了表达式语言中的调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用EL( 表达语言 )?

How can I invoke a method in JSP using EL (Expression Language)?

例如:

<c:forEach var="item" items="${listStr}" begin="0" end="2" step="2">
    <p>${item.indexOf("h")}</p>
</c:forEach>

在这里,item是类型为java.lang.String的对象.在Tomcat上运行时,这会导致错误.

Here, the item is an object of type java.lang.String. This causes errors when run on Tomcat.

推荐答案

仅从EL 2.2开始才支持.这又与Servlet 3.0紧密相关.因此,如果确保使用Servlet 3.0兼容的web.xml声明将Servlet 3.0兼容的容器(Tomcat 7,Glassfish 3等)定位为目标,那么它将按照您的预期方式工作.但是,如果您以较旧版本的servlet容器为目标,或者具有较旧版本的甚至是错误的web.xml根声明,那么它将不起作用.

This is only supported since EL 2.2. This goes in turn hand in hand with Servlet 3.0. So if you make sure that you target a Servlet 3.0 compatible container (Tomcat 7, Glassfish 3, etc) with a Servlet 3.0 compatible web.xml declaration, then it'll just work the way you intend. If you're however targeting an older versioned servlet container, or have an older versioned or even the wrong web.xml root declaration, then it won't work.

更新:您的特定问题可能是由Tomcat 7中的错误引起的.它无法根据给定的参数找到正确的重载方法.您的表达式在Glassfish 3中可以正常工作.所有非重载方法在Tomcat中也可以正常工作.

Update: Your particular problem is likely caused by a bug in Tomcat 7. It doesn't find the right overloaded method based on the given argument. Your expression works fine in Glassfish 3. All non-overloaded methods should work just fine in Tomcat.

这篇关于表达式语言中的调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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