Element Syntax Errors

All container implementations report syntax errors, but details such as the wording of the messages, how much information the message contains, and where the message is written, differ between them. In this chapter, I show examples only of the messages produced by Tomcat.

Let’s first look at how Tomcat reports some typical syntax errors in JSP directives and action elements. Example 9-1 shows a version of the easy.jsp page from Chapter 5 with a syntax error.

Example 9-1. Improperly terminated directive (error1.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>

The syntax error here is that the page directive on the first line isn’t closed properly with %>; the percent sign is missing. Figure 9-1 shows what Tomcat has to say about it.

Error message about an unterminated JSP directive
Figure 9-1. Error message about an unterminated JSP directive

Tomcat reports the error by sending an error message to the browser. This is the default behavior for Tomcat, but it’s not mandated by the JSP specification. The specification requires only that a response with the HTTP status code for a severe error (500) is returned, but how a JSP container reports the details is vendor-specific. For instance, the error message ...

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.