Expression Language Syntax Errors

Prior to JSP 2.0, how well EL syntax errors were reported varied between JSTL implementations and web containers, because the EL wasn’t part of the JSP specification. Starting with JSP 2.0, the EL is part of the JSP specification, and all containers are required to analyze the syntax of EL expressions (in attribute values or directly in the template text) during the translation phase and report all syntax errors it finds.

As with the element syntax error messages, the details differ between containers, but let’s look at a few EL syntax error examples in this section so you can see what to expect when you use the EL with Tomcat. Other implementations may do better (or worse), but these examples illustrate what to look for.

Example 9-5 shows a page with a subtle syntax error: the curly braces are missing in the EL expression.

Example 9-5. Missing both curly braces (error5.jsp)
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head>
    <title>JSP is Easy</title>
  </head>
  <body bgcolor="white">
  
    <h1>JSP is as easy as ...</h1>
  
    1 + 2 + 3 = <c:out value="$1 + 2 + 3" />
  
  </body>
</html>

This is an easy mistake to make, but it’s not recognized as a syntax error at all. To the container, this means that the value is a plain-text value, not an expression. When used with the <c:out> action, it’s easy to figure out what’s wrong because the text value is added to the response as is instead of the being evaluated: ...

Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.