Java 表达式语言和 Eclipse 警告:“项目”不支持运行时表达式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3530994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 01:35:17  来源:igfitidea点击:

Expression Language & Eclipse warning: "items" does not support runtime expressions

javaeclipsejspjstlel

提问by fasseg

i have the following JSP:

我有以下 JSP:

<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page isELIgnored="false"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><c:out value="${it.title}"/></title>
    </head>
    <body>
        <c:forEach var="speaker" items="${it.speakers}" varStatus="stat">
            <ul>
                <li><c:out value="${speaker.person.firstName}" /> <c:out value="${speaker.person.lastName}" />, <c:out value="${speaker.person.address.city.zip}" /> <c:out value="${speaker.person.address.city.name}" /></li>
            </ul> 
        </c:forEach>
    </body>
</html>

Eclipse warns me about every instance of EL Expressions in my code:

Eclipse 警告我代码中的每个 EL 表达式实例:

Warning [line 10]: "value" does not support runtime expressions
Warning [line 13]: "items" does not support runtime expressions
...

this is however not true, EL gets evaluated correctly by the server.

然而事实并非如此,EL 被服务器正确评估。

Can anyone hint me in the right direction why eclipse is warning me about those EL expressions?

任何人都可以向我暗示正确的方向,为什么 eclipse 会警告我关于那些 EL 表达式?

采纳答案by axtavt

Your taglib directive imports a JSTL 1.0 taglib. It should be JSTL 1.1 instead (note the difference in URI):

您的 taglib 指令导入一个 JSTL 1.0 taglib。它应该是 JSTL 1.1(注意 URI 的区别):

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  

回答by Andreas Dolk

Possible solution (found here):

可能的解决方案(在这里找到):

Twin Libraries

The JSTL tag libraries come in two versions which differ only in the way they support the use of runtime expressions for attribute values.

In the JSTL-RT tag library, expressions are specified in the page's scripting language. This is exactly how things currently work in current tag libraries.

In the JSTL-EL tag library, expressions are specified in the JSTL expression language. An expression is a String literal in the syntax of the EL.

When using the EL tag library you cannot pass a scripting language expression for the value of an attribute. This rule makes it possible to validate the syntax of an expression at translation time.

双图书馆

JSTL 标记库有两个版本,区别仅在于它们支持对属性值使用运行时表达式的方式。

在 JSTL-RT 标记库中,表达式是用页面的脚本语言指定的。这正是当前标签库中当前工作的方式。

在 JSTL-EL 标记库中,表达式是用 JSTL 表达式语言指定的。表达式是 EL 语法中的字符串文字。

使用 EL 标记库时,您不能为属性值传递脚本语言表达式。此规则可以在翻译时验证表达式的语法。

So maybe your eclipse and the server use different tag libraries.

所以也许你的 eclipse 和服务器使用不同的标签库。

回答by Kurt_Zhu

try this: change this:

试试这个:改变这个:

<%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>

to yes:

是:

<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>

hope it works for you. I got this from www.csdn.net.

希望对你有效。我是从 www.csdn.net 得到的。