Identifying a JSP Document

The container needs help to recognize a JSP page as a page using the XML syntax. A JSP 2.0 container follows these rules, in this order:

  • The requested page has an extension matching the URL pattern of a JSP group declaration in the web.xml file with <is-xml> set to true, as described earlier.

  • The requested page has the .jspx extension, unless this extension has been disabled by a JSP group with <is-xml> set to false. For a tag file in XML syntax, the .tagx extension must be used.

  • The requested page is identified as a JSP page (through the default .jsp extension or an extension defined by a JSP group declaration) and its root element is <jsp:root>.

The third rule was the only one supported by JSP 1.2, as I mentioned earlier, and it’s primarily kept for backward compatibility. For new applications, you probably want to rely on one of the first two rules instead.

Let’s use a simple JSP Document to discuss the syntax requirements in more detail. Example 17-10 shows a JSP Document that illustrates most of the things you need to consider, as well as the main features available for this format.

Example 17-10. A JSP Document (jspdocument.jspx)
                     <html xmlns="http://www.w3c.org/1999/xhtml" xmlns:jsp="http://java.sun.com/JSP/Page" xml:lang="en" lang="en"> <jsp:output doctype-root-element="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> <jsp:directive.page contentType="text/html" /> ...

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.