Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
509 views
in Technique[技术] by (71.8m points)

jsp - Call methods in Expression Language

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

For example:

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

See also:


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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...