简体   繁体   English

JSTL为什么在Tomcat 8中抱怨一个名为“ Error”的变量

[英]Why does JSTL complain about a variable called “Error” with Tomcat 8

We have a Web Application that worked absolutely fine using Tomcat 7. However when we deployed it on Tomcat 8 we always saw an error on the HTML page: 我们有一个Web应用程序,使用Tomcat 7绝对可以正常工作。但是,当我们将其部署在Tomcat 8上时,我们总是在HTML页面上看到错误:

Error
javax.el.ELClass@550077ee 

The HTML page is created using JSPs and JSTL. HTML页面是使用JSP和JSTL创建的。 The JSTL code for the error area is: 错误区域的JSTL代码为:

<c:if test="${Error!=null}">
  <span>${Error}</span>
</c:if>

By simply changing the variable being passed from the Java side to anything but "Error" (eg XXXError) then the issue disappears. 通过简单地将从Java端传递的变量更改为除“错误”(例如XXXError)以外的任何内容,问题就消失了。

So can anyone explain what the problem is? 谁能解释这个问题是什么? I'll assume "Error" is a reserved word, but why did this affect Tomcat 8 and not Tomcat 7? 我假定“错误”是保留字,但是为什么这会影响Tomcat 8而不影响Tomcat 7?

Thanks, 谢谢,

Phil 菲尔

First thing to be aware of here is that Tomcat 8 comes with EL 3.0, and that is quite a bit different than EL 2.2 which comes with Tomcat 7. If you haven't done so yet, you might want to read up on some of the differences, which include collection streams, lambdas and some other small improvements like static accessors, assignment and collection literals. 首先要注意的是Tomcat 8随附EL 3.0,这与Tomcat 7随附的EL 2.2有很大不同。如果您尚未这样做,则可能需要阅读其中的一些内容。区别包括集合流,lambda和其他一些小的改进,例如静态访问器,赋值和集合文字。

As far as the behavior you're seeing with Error , if you think of it as a class (java.lang.Error) it makes more sense. 至于使用Error看到的行为,如果将其视为一个类(java.lang.Error),则更有意义。 In that case you have Error, which is a class and will never be null, which means your c:if block will always be executed. 在那种情况下,您有Error,这是一个类,并且永远不会为null,这意味着您的c:if块将始终被执行。 Thus you end up with the evaluation of Error the class being included in your output. 因此,您最终得到对Error的评估,该类包含在输出中。

To avoid clashes like this, consider not using upper case letters as the first character in your variables names. 为避免此类冲突,请考虑不要在变量名称中使用大写字母作为第一个字符。 If you had gone with error instead of Error , you wouldn't have seen this problem. 如果您遇到了错误而不是Error ,那么您将不会看到此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM