Phil
Phil

Reputation: 1927

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:

Error
javax.el.ELClass@550077ee 

The HTML page is created using JSPs and JSTL. The JSTL code for the error area is:

<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" (e.g. XXXError) then the issue disappears.

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?

Thanks,

Phil

Upvotes: 2

Views: 312

Answers (1)

Daniel Mikusa
Daniel Mikusa

Reputation: 15006

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.

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. 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. Thus you end up with the evaluation of Error the class being included in your output.

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.

Upvotes: 3

Related Questions